-
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: add loading view * feat: add auth routing * feat: set accessToken to localStorage * fix: remove /auth paths * feat: handle token access
- Loading branch information
Showing
8 changed files
with
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const ACCESS_TOKEN = 'access_token'; |
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,6 +1,4 @@ | ||
export interface User { | ||
memberId: number; | ||
nickname?: string; | ||
accessToken?: string; | ||
refrehToken?: string; | ||
nickname: string; | ||
} |
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 |
---|---|---|
@@ -1,18 +1,36 @@ | ||
import { ACCESS_TOKEN } from 'src/constants/localStorage'; | ||
import { create } from 'zustand'; | ||
|
||
import { User } from '@interfaces/models/user'; | ||
import { persist } from 'zustand/middleware'; | ||
|
||
interface AuthState { | ||
user: User | null; | ||
isLoggedIn: boolean; | ||
} | ||
|
||
interface AuthAction { | ||
setUser: (user: User) => void; | ||
login: () => boolean; | ||
logout: () => void; | ||
} | ||
|
||
export const useAuthStore = create<AuthState & AuthAction>((set) => ({ | ||
user: null, | ||
setUser: (user: User) => { | ||
set({ user: user }); | ||
}, | ||
})); | ||
export const useAuthStore = create( | ||
persist<AuthState & AuthAction>( | ||
(set) => ({ | ||
isLoggedIn: false, | ||
login: () => { | ||
const userLocalStorage = localStorage.getItem(ACCESS_TOKEN); | ||
if (userLocalStorage) { | ||
set({ isLoggedIn: true }); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}, | ||
logout: () => { | ||
set({ isLoggedIn: false }); | ||
localStorage.clear(); | ||
}, | ||
}), | ||
{ | ||
name: 'userLoginStatus', | ||
} | ||
) | ||
); |