Skip to content

Commit

Permalink
feat: create api request function
Browse files Browse the repository at this point in the history
sign up, sigin in, sign out
token refresh
get today question
get all members

#19
  • Loading branch information
timepresent95 committed Aug 12, 2024
1 parent 23fed3e commit 75be60a
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/api/auth.ts
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};
14 changes: 14 additions & 0 deletions src/api/member.ts
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};
14 changes: 14 additions & 0 deletions src/api/quetions.ts
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};

0 comments on commit 75be60a

Please sign in to comment.