-
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.
feat(tokens): access and refresh token (#7)
* add and refactor to getATWithRefreshToken * refactor to handle 2 types * add delete refresh token * add PostTokenResponse type * add logout button, get refresh token, minor fix * satisfy linter, tsc * add build to ci * fix test
- Loading branch information
Showing
14 changed files
with
240 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { deleteRefreshToken } from "@/utils/token" | ||
import { useCallback } from "react" | ||
|
||
type LogoutButtonProps = { | ||
className?: string | ||
} | ||
const LogoutButton = ({ className }: LogoutButtonProps) => { | ||
const handleLogout = useCallback(() => { | ||
deleteRefreshToken() | ||
window.location.reload() | ||
}, []) | ||
|
||
return ( | ||
<div className={className}> | ||
<span> | ||
<button type="submit" onClick={handleLogout}> | ||
Logout | ||
</button> | ||
</span> | ||
</div> | ||
) | ||
} | ||
|
||
export default LogoutButton |
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,17 @@ | ||
import { createContext } from "use-context-selector" | ||
|
||
export type AuthContextType = { | ||
accessToken?: string, | ||
refreshToken?: string | null, | ||
readonly accessToken: string | null; | ||
readonly refreshToken: string | null; | ||
setAccessToken(token: string): void; | ||
setRefreshToken(token: string): void; | ||
} | ||
|
||
const AuthContext = createContext<AuthContextType>({}) | ||
const AuthContext = createContext<AuthContextType>({ | ||
accessToken: null, | ||
refreshToken: null, | ||
setAccessToken: () => { }, | ||
setRefreshToken: () => { } | ||
}) | ||
|
||
export default AuthContext |
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.