-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: localStorage 작업 관리를 위한 storageHelper 모듈 생성
- 액세스 토큰과 리프레시 토큰을 설정, 가져오기, 삭제하는 함수 추가. - 사용자 데이터를 설정, 가져오기, 삭제하는 함수 추가. - localStorage에서 모든 토큰과 사용자 데이터를 지우는 함수 추가. - signUpUser와 loginUser 함수를 수정하여 storageHelper를 사용해 토큰과 사용자 데이터를 관리.
- Loading branch information
Showing
5 changed files
with
69 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { User } from "../types"; | ||
|
||
export const setAccessToken = (token: string): void => { | ||
localStorage.setItem("accessToken", token); | ||
}; | ||
|
||
export const getAccessToken = (): string | null => { | ||
return localStorage.getItem("accessToken"); | ||
}; | ||
|
||
export const removeAccessToken = (): void => { | ||
localStorage.removeItem("accessToken"); | ||
}; | ||
|
||
export const setRefreshToken = (token: string): void => { | ||
localStorage.setItem("refreshToken", token); | ||
}; | ||
|
||
export const getRefreshToken = (): string | null => { | ||
return localStorage.getItem("refreshToken"); | ||
}; | ||
|
||
export const removeRefreshToken = (): void => { | ||
localStorage.removeItem("refreshToken"); | ||
}; | ||
|
||
export const clearTokens = (): void => { | ||
removeAccessToken(); | ||
removeRefreshToken(); | ||
}; | ||
|
||
export const setUser = (user: User): void => { | ||
localStorage.setItem("user", JSON.stringify(user)); | ||
}; | ||
|
||
export const getUser = () => { | ||
const user = localStorage.getItem("user"); | ||
return user ? JSON.parse(user) : null; | ||
}; | ||
|
||
export const removeUser = (): void => { | ||
localStorage.removeItem("user"); | ||
}; | ||
|
||
export const clearStorage = (): void => { | ||
clearTokens(); | ||
removeUser(); | ||
}; |