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