add: auth proxy to menu route
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"name": "Zhivan - ژیوان",
|
||||
"short_name": "Zhivan",
|
||||
"start_url": "/zhivan",
|
||||
"scope": "/",
|
||||
"scope": "/zhivan",
|
||||
"id": "/zhivan",
|
||||
"display": "standalone",
|
||||
"display_override": [
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from '@/app/auth/layout'
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from '@/app/auth/login/page'
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from '@/app/auth/page'
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from '@/app/auth/reset-password/page'
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from '@/app/auth/signup/page'
|
||||
@@ -8,7 +8,7 @@ import React, {
|
||||
useTransition
|
||||
} from 'react'
|
||||
import { useAuthStore } from '@/zustand/authStore'
|
||||
import { redirect, useRouter } from 'next/navigation'
|
||||
import { redirect, useParams, useRouter } from 'next/navigation'
|
||||
import StepEnterPassword from '@/features/auth/components/StepEnterPassword'
|
||||
import StepEnterNumber from '@/features/auth/components/StepEnterNumber'
|
||||
import { AUTH_PAGE_ELEMENT, AUTH_STEP } from '@/enums'
|
||||
@@ -35,12 +35,14 @@ function AuthIndex ({}: Props) {
|
||||
const loginMutation = useLogin()
|
||||
const { run: runUserExistCheck } = useCheckUserExistsLazy()
|
||||
const router = useRouter()
|
||||
const { name } = useParams()
|
||||
const basePath = `/${name ?? ''}`
|
||||
|
||||
useEffect(() => {
|
||||
if (isAuthenticated) {
|
||||
redirect('/')
|
||||
redirect(basePath)
|
||||
}
|
||||
}, [isAuthenticated])
|
||||
}, [isAuthenticated, basePath])
|
||||
|
||||
const onChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
if (e.target.name == AUTH_PAGE_ELEMENT.INPUT_PHONE) {
|
||||
@@ -86,7 +88,7 @@ function AuthIndex ({}: Props) {
|
||||
if (userExists) {
|
||||
setStep(AUTH_STEP.ENTER_CURRENT_PASSWORD)
|
||||
} else {
|
||||
router.replace('/auth/signup')
|
||||
router.replace(`${basePath}/auth/signup`)
|
||||
}
|
||||
} else if (
|
||||
step == AUTH_STEP.ENTER_OTP ||
|
||||
@@ -102,7 +104,7 @@ function AuthIndex ({}: Props) {
|
||||
try {
|
||||
await loginMutation.mutateAsync({ phone: number, password })
|
||||
console.log('Signed in')
|
||||
redirect('/')
|
||||
router.replace(basePath)
|
||||
} catch (e) {
|
||||
console.error('Could not Login: ', e)
|
||||
}
|
||||
@@ -132,7 +134,7 @@ function AuthIndex ({}: Props) {
|
||||
})
|
||||
try {
|
||||
console.log('Signed in')
|
||||
redirect('/')
|
||||
router.replace(basePath)
|
||||
} catch (e) {
|
||||
console.error('Could not Login: ', e)
|
||||
}
|
||||
|
||||
@@ -22,10 +22,8 @@ function AuthIndex ({}: Props) {
|
||||
const user_temp_store = useAuthTempStore(state => state.user)
|
||||
const [number, setNumber] = useState(user_temp_store?.number ?? '')
|
||||
const [isPending, startTransition] = useTransition()
|
||||
|
||||
const isAuthenticated = useAuthStore(state => state.isAuthenticated)
|
||||
const { run: runUserExistCheck } = useCheckUserExistsLazy()
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
useEffect(() => {
|
||||
@@ -61,9 +59,9 @@ function AuthIndex ({}: Props) {
|
||||
mustLogin: userExists
|
||||
})
|
||||
if (userExists) {
|
||||
router.push('/auth/login')
|
||||
router.push('auth/login')
|
||||
} else {
|
||||
router.push('/auth/signup')
|
||||
router.push('auth/signup')
|
||||
}
|
||||
} catch (ex) {
|
||||
console.error(ex)
|
||||
@@ -76,9 +74,9 @@ function AuthIndex ({}: Props) {
|
||||
mustLogin: !number.endsWith('0')
|
||||
})
|
||||
if (number.endsWith('0')) {
|
||||
router.push('/auth/signup')
|
||||
router.push('auth/login')
|
||||
} else {
|
||||
router.push('/auth/login')
|
||||
router.push('auth/login')
|
||||
}
|
||||
/* END OF DEV SECTION */
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import React, {
|
||||
useTransition
|
||||
} from 'react'
|
||||
import { useAuthStore } from '@/zustand/authStore'
|
||||
import { redirect, useRouter } from 'next/navigation'
|
||||
import { useParams, useRouter } from 'next/navigation'
|
||||
import StepEnterNumber from '@/features/auth/components/StepEnterNumber'
|
||||
import StepEnterOtp from '@/features/auth/components/StepEnterOtp'
|
||||
import { AUTH_PAGE_ELEMENT, AUTH_STEP } from '@/enums'
|
||||
@@ -50,12 +50,8 @@ function AuthIndex ({}: Props) {
|
||||
const { run: runOtpValidation } = useOtpValidation()
|
||||
const { run: runResetPassword } = useResetPassword()
|
||||
const router = useRouter()
|
||||
|
||||
useEffect(() => {
|
||||
if (isAuthenticated) {
|
||||
redirect('/')
|
||||
}
|
||||
}, [isAuthenticated])
|
||||
const { name } = useParams()
|
||||
const basePath = `/${name ?? ''}`
|
||||
|
||||
useEffect(() => {
|
||||
if (step === AUTH_STEP.ENTER_OTP) {
|
||||
@@ -170,7 +166,11 @@ function AuthIndex ({}: Props) {
|
||||
otp: otp
|
||||
})
|
||||
console.log('Password changed')
|
||||
redirect('/')
|
||||
if (isAuthenticated) {
|
||||
router.replace(basePath)
|
||||
} else {
|
||||
router.replace(`${basePath}/auth`)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Could not reset password: ', e)
|
||||
}
|
||||
@@ -200,7 +200,11 @@ function AuthIndex ({}: Props) {
|
||||
})
|
||||
try {
|
||||
console.log('Password changed')
|
||||
router.replace('/auth')
|
||||
if (isAuthenticated) {
|
||||
router.replace(basePath)
|
||||
} else {
|
||||
router.replace(`${basePath}/auth`)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Could not reset password: ', e)
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import React, {
|
||||
useTransition
|
||||
} from 'react'
|
||||
import { useAuthStore } from '@/zustand/authStore'
|
||||
import { redirect, useRouter } from 'next/navigation'
|
||||
import { redirect, useParams, useRouter } from 'next/navigation'
|
||||
import StepEnterNumber from '@/features/auth/components/StepEnterNumber'
|
||||
import StepEnterOtp from '@/features/auth/components/StepEnterOtp'
|
||||
import { AUTH_PAGE_ELEMENT, AUTH_STEP } from '@/enums'
|
||||
@@ -47,12 +47,14 @@ function AuthIndex ({}: Props) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { run: runOtpValidation } = useOtpValidation()
|
||||
const router = useRouter()
|
||||
const { name } = useParams()
|
||||
const basePath = `/${name ?? ''}`
|
||||
|
||||
useEffect(() => {
|
||||
if (isAuthenticated) {
|
||||
redirect('/')
|
||||
redirect(basePath)
|
||||
}
|
||||
}, [isAuthenticated])
|
||||
}, [isAuthenticated, basePath])
|
||||
|
||||
useEffect(() => {
|
||||
if (step === AUTH_STEP.ENTER_OTP) {
|
||||
@@ -134,7 +136,7 @@ function AuthIndex ({}: Props) {
|
||||
mustLogin: userExists
|
||||
})
|
||||
if (userExists) {
|
||||
setStep(AUTH_STEP.ENTER_CURRENT_PASSWORD)
|
||||
router.replace(`${basePath}/auth/login`)
|
||||
} else {
|
||||
setStep(AUTH_STEP.ENTER_OTP)
|
||||
}
|
||||
@@ -159,7 +161,7 @@ function AuthIndex ({}: Props) {
|
||||
try {
|
||||
await signupMutation.mutateAsync({ phone: number, password })
|
||||
console.log('Signed up')
|
||||
redirect('/')
|
||||
router.replace(basePath)
|
||||
} catch (e) {
|
||||
console.error('Could not signup: ', e)
|
||||
}
|
||||
@@ -189,8 +191,7 @@ function AuthIndex ({}: Props) {
|
||||
})
|
||||
try {
|
||||
console.log('Signed up')
|
||||
// redirect('/')
|
||||
router.replace('/') // TODO: redirect to target menu page
|
||||
router.replace(basePath)
|
||||
} catch (e) {
|
||||
console.error('Could not signup: ', e)
|
||||
}
|
||||
|
||||
+8
-5
@@ -1,11 +1,14 @@
|
||||
import Link from "next/link";
|
||||
import Link from 'next/link'
|
||||
|
||||
export default function Home () {
|
||||
return (
|
||||
<div>
|
||||
<Link href={'/auth'}>Auth</Link><br/>
|
||||
<Link href={'/menu'}>Menu</Link><br/>
|
||||
<Link href={'/'}>Index</Link><br/>
|
||||
<Link href={'/auth'}>Auth</Link>
|
||||
<br />
|
||||
<Link href={'/zhivan'}>Menu</Link>
|
||||
<br />
|
||||
<Link href={'/'}>Index</Link>
|
||||
<br />
|
||||
</div>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user