-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: consolidation of security levels undertaken
Add a refresh token mechanism to extend the duration of the login state. Intercept interface request token dynamic verification.
- Loading branch information
Showing
12 changed files
with
147 additions
and
47 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
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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useRouter } from 'next/navigation'; | ||
import { Middleware, SWRHook } from 'swr'; | ||
|
||
import { useStore } from '@/store'; | ||
|
||
import { ErrorCodeEnum } from 'shared'; | ||
|
||
const authMiddleware: Middleware = | ||
(useSWRNext: SWRHook) => (key, fetcher, config) => { | ||
// Handle the next middleware, or the `useSWR` hook if this is the last one. | ||
const swr = useSWRNext(key, fetcher, config); | ||
|
||
// After hook runs... | ||
// @ts-ignore | ||
if (swr.data?.success === false) { | ||
// @ts-ignore | ||
if (swr.data?.code === ErrorCodeEnum.AuthFail) { | ||
useStore().clearAuthToken(); | ||
useRouter().push('/auth'); | ||
throw new Error('Auth failed'); | ||
} | ||
} | ||
return swr; | ||
}; | ||
export default authMiddleware; |
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
Oops, something went wrong.