generated from GSM-MSG/MSG-Repository-Generator
-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
c1d9712
commit fd8d888
Showing
95 changed files
with
781 additions
and
819 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,10 @@ | ||
import axios from 'axios' | ||
import qs from 'qs' | ||
import ParamsFilter from '@lib/ParamsFilter' | ||
import axiosRetry from 'axios-retry' | ||
|
||
const axiosApi = axios.create({ | ||
'axios-retry': { | ||
retries: 3, | ||
retryCondition: (e) => e.response?.status === 401, | ||
}, | ||
paramsSerializer: (params) => | ||
qs.stringify(ParamsFilter(params), { arrayFormat: 'repeat' }), | ||
}) | ||
|
||
axiosRetry(axiosApi, { | ||
retries: 3, | ||
retryDelay: (retryCount) => { | ||
return retryCount * 1000 | ||
}, | ||
shouldResetTimeout: true, | ||
retryCondition: (error) => { | ||
return ( | ||
axiosRetry.isNetworkOrIdempotentRequestError(error) || | ||
error.response?.status === 401 | ||
) | ||
}, | ||
}) | ||
|
||
export default axiosApi |
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,2 +1 @@ | ||
export { default as axiosApi } from './axiosApi' | ||
export { default as rtkApi } from './rtkApi' |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as LoggedInResDto } from './res/LoggedInResDto' | ||
|
||
export type { LoggedInResType } from './res/LoggedInResDto' |
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,26 @@ | ||
import { z } from 'zod' | ||
import Role from '@/types/Role' | ||
|
||
const RoleSchema = z.enum([ | ||
Role.ROLE_STUDENT, | ||
Role.ROLE_TEACHER, | ||
Role.ROLE_DIRECTOR, | ||
Role.ROLE_HOMEROOM, | ||
Role.ROLE_PRINCIPAL, | ||
Role.ROLE_DEPUTY_PRINCIPAL, | ||
]) | ||
|
||
export const successDto = z.object({ | ||
isLoggedIn: z.literal(true), | ||
role: RoleSchema, | ||
}) | ||
|
||
export const failDto = z.object({ | ||
isLoggedIn: z.literal(false), | ||
}) | ||
|
||
const LoggedInResDto = z.discriminatedUnion('isLoggedIn', [successDto, failDto]) | ||
|
||
export type LoggedInResType = z.infer<typeof LoggedInResDto> | ||
|
||
export default LoggedInResDto |
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
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,9 @@ | ||
import Token from '@lib/Token' | ||
import Cookies from 'cookies' | ||
|
||
const clearAuthCookies = (cookies: Cookies) => { | ||
cookies.set(Token.ACCESS_TOKEN, '', { maxAge: -1 }) | ||
cookies.set(Token.REFRESH_TOKEN, '', { maxAge: -1 }) | ||
} | ||
|
||
export default clearAuthCookies |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { decode } from 'jsonwebtoken' | ||
import { z } from 'zod' | ||
import Role from '@/types/Role' | ||
|
||
const RoleSchema = z.enum([ | ||
Role.ROLE_STUDENT, | ||
Role.ROLE_TEACHER, | ||
Role.ROLE_DIRECTOR, | ||
Role.ROLE_HOMEROOM, | ||
Role.ROLE_PRINCIPAL, | ||
Role.ROLE_DEPUTY_PRINCIPAL, | ||
]) | ||
|
||
const getRole = (token: string) => { | ||
const payload = decode(token, { json: true }) | ||
|
||
const result = RoleSchema.safeParse(payload?.ROLE) | ||
if (!result.success) return | ||
|
||
return result.data | ||
} | ||
|
||
export default getRole |
Oops, something went wrong.