diff --git a/public/manifests/zhivan/manifest.json b/public/manifests/zhivan/manifest.json index 05a1d39..340d5d7 100644 --- a/public/manifests/zhivan/manifest.json +++ b/public/manifests/zhivan/manifest.json @@ -2,7 +2,7 @@ "name": "Zhivan - ژیوان", "short_name": "Zhivan", "start_url": "/zhivan", - "scope": "/", + "scope": "/zhivan", "id": "/zhivan", "display": "standalone", "display_override": [ diff --git a/src/app/[name]/(Proxy)/auth/layout.tsx b/src/app/[name]/(Proxy)/auth/layout.tsx new file mode 100644 index 0000000..5b267bf --- /dev/null +++ b/src/app/[name]/(Proxy)/auth/layout.tsx @@ -0,0 +1 @@ +export { default } from '@/app/auth/layout' diff --git a/src/app/[name]/(Proxy)/auth/login/page.tsx b/src/app/[name]/(Proxy)/auth/login/page.tsx new file mode 100644 index 0000000..8e0cddf --- /dev/null +++ b/src/app/[name]/(Proxy)/auth/login/page.tsx @@ -0,0 +1 @@ +export { default } from '@/app/auth/login/page' diff --git a/src/app/[name]/(Proxy)/auth/page.tsx b/src/app/[name]/(Proxy)/auth/page.tsx new file mode 100644 index 0000000..97f9ac7 --- /dev/null +++ b/src/app/[name]/(Proxy)/auth/page.tsx @@ -0,0 +1 @@ +export { default } from '@/app/auth/page' diff --git a/src/app/[name]/(Proxy)/auth/reset-password/page.tsx b/src/app/[name]/(Proxy)/auth/reset-password/page.tsx new file mode 100644 index 0000000..c8d5c2c --- /dev/null +++ b/src/app/[name]/(Proxy)/auth/reset-password/page.tsx @@ -0,0 +1 @@ +export { default } from '@/app/auth/reset-password/page' diff --git a/src/app/[name]/(Proxy)/auth/signup/page.tsx b/src/app/[name]/(Proxy)/auth/signup/page.tsx new file mode 100644 index 0000000..046b7da --- /dev/null +++ b/src/app/[name]/(Proxy)/auth/signup/page.tsx @@ -0,0 +1 @@ +export { default } from '@/app/auth/signup/page' diff --git a/src/app/auth/login/page.tsx b/src/app/auth/login/page.tsx index 4dde800..6de8d96 100644 --- a/src/app/auth/login/page.tsx +++ b/src/app/auth/login/page.tsx @@ -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) => { 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) } diff --git a/src/app/auth/page.tsx b/src/app/auth/page.tsx index 61b2e1f..ca97e25 100644 --- a/src/app/auth/page.tsx +++ b/src/app/auth/page.tsx @@ -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 */ } diff --git a/src/app/auth/forgot-password/page.tsx b/src/app/auth/reset-password/page.tsx similarity index 94% rename from src/app/auth/forgot-password/page.tsx rename to src/app/auth/reset-password/page.tsx index 47b1443..3abfebd 100644 --- a/src/app/auth/forgot-password/page.tsx +++ b/src/app/auth/reset-password/page.tsx @@ -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) } diff --git a/src/app/auth/signup/page.tsx b/src/app/auth/signup/page.tsx index 3aa73f9..01e53be 100644 --- a/src/app/auth/signup/page.tsx +++ b/src/app/auth/signup/page.tsx @@ -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) } diff --git a/src/app/page.tsx b/src/app/page.tsx index 4bf1ca8..2418fd6 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,11 +1,14 @@ -import Link from "next/link"; +import Link from 'next/link' -export default function Home() { +export default function Home () { return (
- Auth
- Menu
- Index
+ Auth +
+ Menu +
+ Index +
- ); + ) }