Skip to content

Commit 72bd421

Browse files
committed
feat: modify auth api
sync api doc #19
1 parent 4d51a6b commit 72bd421

File tree

2 files changed

+56
-33
lines changed

2 files changed

+56
-33
lines changed

src/api/auth.ts

+50-33
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
import {kyInstance} from './ky';
2+
import {authApis} from './routes';
23

3-
import {BirthType, GoupRole, OAuthAgent} from '@/types';
4-
//NOTE: 아직 BE에서 토큰 재발급 관련 API 미기획
5-
// import {getEncryptStorage} from '@/utils';
4+
import {AlertToken, BirthType, GoupRole, OAuthAgent} from '@/types';
5+
import {createUrl} from '@/utils/url';
66

7-
type RequestSignUp = {
7+
type BodySignUp = {
88
nickName: string;
99
OAuthProvider: OAuthAgent;
1010
birth: Date;
1111
birthType: BirthType;
1212
email: String;
1313
groupRole: GoupRole;
1414
familyCode: null | string;
15-
alertToken: {
16-
deviceId: string;
17-
type: 'FCM';
18-
value: string;
19-
};
15+
alertToken: AlertToken;
2016
};
2117

2218
type ResponseToken = {
@@ -25,45 +21,66 @@ type ResponseToken = {
2521
grantType: string;
2622
};
2723

28-
async function postSignUp(body: RequestSignUp) {
29-
return (await kyInstance
30-
.post('auth/oauth/sign-up', {json: body})
31-
.json()) as ResponseToken;
24+
async function postSignUp(body: BodySignUp) {
25+
return await kyInstance
26+
.post(authApis.signUp, {json: body})
27+
.json<ResponseToken>();
3228
}
3329

34-
type RequestSignIn = {
30+
type BodySignIn = {
3531
OAuthProvider: OAuthAgent;
3632
AuthorizationCode: string;
3733
};
3834

39-
async function postSignIn(body: RequestSignIn) {
40-
return (await kyInstance
41-
.post('auth/oauth/sign-in', {json: body})
42-
.json()) as ResponseToken;
35+
async function postSignIn(body: BodySignIn) {
36+
return await kyInstance
37+
.post(authApis.signIn, {json: body})
38+
.json<ResponseToken>();
4339
}
4440

4541
async function getSignOut() {
46-
return await kyInstance.get('auth/sign-out').json();
42+
return await kyInstance.get(authApis.signOut).json();
4743
}
4844

49-
//NOTE: 아직 BE에서 토큰 재발급 관련 API 미기획
50-
// async function getAccessToken() {
51-
// const refreshToken = await getEncryptStorage('refreshToken');
45+
async function reIssueToken() {
46+
return await kyInstance.patch(authApis.reIssueToken).json<ResponseToken>();
47+
}
5248

53-
// return (await kyInstance
54-
// .get('auth/token/refresh', {
55-
// headers: {
56-
// Authorization: `Bearer ${refreshToken}`,
57-
// },
58-
// })
59-
// .json()) as ResponseToken;
60-
// }
49+
type QueryValidateFamilyCode = {
50+
familyCode: string;
51+
};
6152

53+
type ResponseValidateFamilyCode = {
54+
isValidate: boolean;
55+
};
56+
57+
async function validateFamilyCode(query: QueryValidateFamilyCode) {
58+
const apiUrl = createUrl(authApis.validateFamilyCode, {query});
59+
return await kyInstance.get(apiUrl).json<ResponseValidateFamilyCode>();
60+
}
61+
62+
type BodyReRegistrationAlertToken = {
63+
userId: number;
64+
} & AlertToken;
65+
66+
async function reRegistrationAlertToken(body: BodyReRegistrationAlertToken) {
67+
return await kyInstance
68+
.patch(authApis.reRegistrationAlertToken, {json: body})
69+
.json();
70+
}
6271
export {
6372
postSignUp,
6473
postSignIn,
6574
getSignOut,
66-
//NOTE: 아직 BE에서 토큰 재발급 관련 API 미기획
67-
// getAccessToken
75+
reIssueToken,
76+
validateFamilyCode,
77+
reRegistrationAlertToken,
78+
};
79+
export type {
80+
BodySignUp,
81+
ResponseToken,
82+
BodySignIn,
83+
QueryValidateFamilyCode,
84+
ResponseValidateFamilyCode,
85+
BodyReRegistrationAlertToken,
6886
};
69-
export type {RequestSignUp, ResponseToken, RequestSignIn};

src/types/auth.ts

+6
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ export type SignInLog = {
44
recentSigninDate: Date; // 최근 접속 시간
55
recentSigninOAuthAgent: OAuthAgent; // 최근 접속시 사용한 로그인 방법
66
};
7+
8+
export type AlertToken = {
9+
deviceId: string;
10+
type: 'FCM';
11+
value: string;
12+
};

0 commit comments

Comments
 (0)