-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] add login login after being successful sign up step
- Loading branch information
1 parent
f97a7e0
commit dbfeabc
Showing
4 changed files
with
81 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,27 @@ | ||
import { defaultInstance } from './httpRequest'; | ||
|
||
const postLogin = async (loginInfo: { email: string; password: string }) => { | ||
console.log('In postLogin', loginInfo); | ||
interface AuthTokenType { | ||
accessToken: string; | ||
refreshToken: string; | ||
} | ||
|
||
const result = await defaultInstance<{ | ||
accessToken: string; | ||
refreshToken: string; | ||
}>({ | ||
const postLogin = async (loginInfo: { email: string; password: string }) => { | ||
const result = await defaultInstance<AuthTokenType>({ | ||
method: 'POST', | ||
url: '/login', | ||
data: loginInfo, | ||
}); | ||
|
||
return result; | ||
}; | ||
|
||
export { postLogin }; | ||
const requestLogout = async () => { | ||
const result = await defaultInstance<AuthTokenType>({ | ||
method: 'GET', | ||
url: '/logout/success', | ||
}); | ||
|
||
return result; | ||
}; | ||
|
||
export { postLogin, requestLogout }; |
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,40 @@ | ||
const ACCESS_TOKEN = 'access_token'; | ||
const REFRESH_TOKEN = 'refresh_token'; | ||
|
||
export const saveAccessToken = (token: string) => { | ||
if (token) { | ||
localStorage.setItem(ACCESS_TOKEN, token); | ||
return true; | ||
} | ||
|
||
throw new Error('Token string is empty!'); | ||
}; | ||
|
||
export const saveRefreshToken = (token: string) => { | ||
if (token) { | ||
localStorage.setItem(REFRESH_TOKEN, token); | ||
return true; | ||
} | ||
|
||
throw new Error('Token string is empty!'); | ||
}; | ||
|
||
export const getAccessToken = () => { | ||
const token = localStorage.getItem(ACCESS_TOKEN); | ||
|
||
if (token) { | ||
return token; | ||
} | ||
|
||
throw new Error('Access token is not erolled!'); | ||
}; | ||
|
||
export const getRefreshToken = () => { | ||
const token = localStorage.getItem(REFRESH_TOKEN); | ||
|
||
if (token) { | ||
return token; | ||
} | ||
|
||
throw new Error('Refresh token is not erolled!'); | ||
}; |