-
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.
sign up, sigin in, sign out token refresh get today question get all members #19
- Loading branch information
1 parent
23fed3e
commit 75be60a
Showing
3 changed files
with
83 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import {kyInstance} from './ky'; | ||
|
||
import {BirthType, GoupRole, OAuthAgent} from '@/types'; | ||
import {getEncryptStorage} from '@/utils'; | ||
|
||
type RequestSignUp = { | ||
nickName: string; | ||
OAuthProvider: OAuthAgent; | ||
birth: Date; | ||
birthType: BirthType; | ||
email: String; | ||
groupRole: GoupRole; | ||
familyCode: null | string; | ||
}; | ||
|
||
type ResponseToken = { | ||
accessToken: string; | ||
refreshToken: string; | ||
}; | ||
|
||
async function postSignUp(body: RequestSignUp) { | ||
return (await kyInstance | ||
.post('auth/oauth/sign-up', {json: body}) | ||
.json()) as ResponseToken; | ||
} | ||
|
||
type RequestSignIn = { | ||
OAuthProvider: OAuthAgent; | ||
AuthorizationCode: string; | ||
}; | ||
|
||
async function postSignIn(body: RequestSignIn) { | ||
return (await kyInstance | ||
.post('auth/oauth/sign-in', {json: body}) | ||
.json()) as ResponseToken; | ||
} | ||
|
||
async function getSignOut() { | ||
return await kyInstance.get('auth/sign-out').json(); | ||
} | ||
|
||
async function getAccessToken() { | ||
const refreshToken = await getEncryptStorage('refreshToken'); | ||
|
||
return (await kyInstance | ||
.get('auth/token/refresh', { | ||
headers: { | ||
Authorization: `Bearer ${refreshToken}`, | ||
}, | ||
}) | ||
.json()) as ResponseToken; | ||
} | ||
|
||
export {postSignUp, postSignIn, getSignOut, getAccessToken}; | ||
export type {RequestSignUp, ResponseToken, RequestSignIn}; |
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,14 @@ | ||
import {kyInstance} from './ky'; | ||
|
||
import {Member} from '@/types'; | ||
|
||
type ResponseMembers = { | ||
members: Member[]; | ||
}; | ||
|
||
async function getMembers() { | ||
return (await kyInstance.get('members').json()) as ResponseMembers; | ||
} | ||
|
||
export {getMembers}; | ||
export type {ResponseMembers}; |
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,14 @@ | ||
import {kyInstance} from './ky'; | ||
|
||
type ResponseTodayQuestion = { | ||
question: string; | ||
}; | ||
|
||
async function getTodayQuestion() { | ||
return (await kyInstance | ||
.get('question/today') | ||
.json()) as ResponseTodayQuestion; | ||
} | ||
|
||
export {getTodayQuestion}; | ||
export type {ResponseTodayQuestion}; |