-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from capstone-maru/dev
release: v0.6.0
- Loading branch information
Showing
129 changed files
with
14,091 additions
and
2,436 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use client'; | ||
|
||
import { MobileChattingBox } from '@/components/chat'; | ||
|
||
export default function Page() { | ||
return <MobileChattingBox />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,90 @@ | ||
'use client'; | ||
|
||
import { isAxiosError } from 'axios'; | ||
import { usePathname, useRouter } from 'next/navigation'; | ||
import { useEffect } from 'react'; | ||
import { useCallback, useLayoutEffect, useState } from 'react'; | ||
|
||
import { | ||
getUserData, | ||
postTokenRefresh, | ||
useAuthActions, | ||
useAuthValue, | ||
} from '@/features/auth'; | ||
import { load } from '@/shared/storage'; | ||
import { load, remove } from '@/shared/storage'; | ||
|
||
export function AuthProvider({ children }: { children: React.ReactNode }) { | ||
const auth = useAuthValue(); | ||
const { login } = useAuthActions(); | ||
const { setAuthUserData, login } = useAuthActions(); | ||
|
||
const router = useRouter(); | ||
const pathName = usePathname(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
|
||
useEffect(() => { | ||
if (pathName === '/login') { | ||
const handleLoginSuccess = useCallback( | ||
(data: { | ||
accessToken: string; | ||
refreshToken: string; | ||
expiresIn: number; | ||
}) => { | ||
login({ | ||
accessToken: data.accessToken, | ||
refreshToken: data.refreshToken, | ||
expiresIn: data.expiresIn, | ||
}); | ||
}, | ||
[login], | ||
); | ||
|
||
const handleLoginError = useCallback( | ||
(err: Error) => { | ||
if (isAxiosError(err)) { | ||
remove({ type: 'local', key: 'refreshToken' }); | ||
if (pathName !== '/') router.replace('/'); | ||
} | ||
}, | ||
[router, pathName], | ||
); | ||
|
||
const checkAndRefreshToken = useCallback(() => { | ||
if (pathName === '/login' || auth != null || isLoading) return; | ||
|
||
const refreshToken = load<string>({ type: 'local', key: 'refreshToken' }); | ||
if (refreshToken == null) { | ||
router.replace('/'); | ||
return; | ||
} | ||
|
||
if (auth === null) { | ||
const refreshToken = load<string>({ type: 'local', key: 'refreshToken' }); | ||
if (refreshToken !== null) { | ||
postTokenRefresh(refreshToken) | ||
.then(({ data }) => { | ||
login({ | ||
accessToken: data.accessToken, | ||
refreshToken, | ||
expiresIn: data.expiresIn, | ||
}); | ||
setIsLoading(true); | ||
postTokenRefresh(refreshToken) | ||
.then(({ data }) => { | ||
handleLoginSuccess(data); | ||
getUserData() | ||
.then(res => { | ||
setAuthUserData(res.data); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
router.replace('/'); | ||
}); | ||
} else { | ||
router.replace('/'); | ||
} | ||
} | ||
}, [auth, login, router, pathName]); | ||
}) | ||
.catch(handleLoginError) | ||
.finally(() => { | ||
setIsLoading(false); | ||
}); | ||
}, [ | ||
pathName, | ||
auth, | ||
isLoading, | ||
handleLoginError, | ||
router, | ||
handleLoginSuccess, | ||
setAuthUserData, | ||
]); | ||
|
||
useLayoutEffect(() => { | ||
checkAndRefreshToken(); | ||
}); | ||
|
||
if (pathName !== '/' && pathName !== '/login' && (isLoading || auth == null)) | ||
return <></>; | ||
return <>{children}</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use client'; | ||
|
||
import { useRouter } from 'next/navigation'; | ||
import { useEffect } from 'react'; | ||
|
||
import { useAuthActions, useAuthValue, useUserData } from '@/features/auth'; | ||
|
||
export function InitialzationProvider({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
const router = useRouter(); | ||
|
||
const auth = useAuthValue(); | ||
const { setAuthUserData } = useAuthActions(); | ||
|
||
const { data: userData } = useUserData(auth?.accessToken != null); | ||
|
||
useEffect(() => { | ||
console.log(userData); | ||
if (userData != null) { | ||
setAuthUserData(userData); | ||
if (userData.initialized) { | ||
router.replace('/profile'); | ||
} | ||
} | ||
}, [userData, router, setAuthUserData]); | ||
|
||
return <>{children}</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
'use client'; | ||
|
||
import { LandingPage, MainPage } from './pages'; | ||
import { MobileLandingPage, MobileMainPage } from './pages/mobile'; | ||
|
||
import { useAuthIsLogin } from '@/features/auth'; | ||
import { useIsMobile } from '@/shared/mobile'; | ||
|
||
export default function Home() { | ||
const isLogin = useAuthIsLogin(); | ||
return <>{isLogin ? <MainPage /> : <LandingPage />}</>; | ||
const isMobile = useIsMobile(); | ||
return ( | ||
<> | ||
{isLogin ? ( | ||
<>{isMobile ? <MobileMainPage /> : <MainPage />}</> | ||
) : ( | ||
<>{isMobile ? <MobileLandingPage /> : <LandingPage />}</> | ||
)} | ||
</> | ||
); | ||
} |
Oops, something went wrong.