Skip to content

Commit 0f4c927

Browse files
authored
Merge pull request #150 from team-ppointer/geat/native/login-#146
[Feat/native/#146] 로그인 페이지 구현
2 parents 2e1b1db + b3a0ce7 commit 0f4c927

File tree

78 files changed

+6548
-1447
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+6548
-1447
lines changed

apps/native/src/apis/authMiddleware.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
setTeacherName,
1616
setTeacherRefreshToken,
1717
} from '@utils/auth';
18-
import { postRefreshToken } from '@apis/controller/auth';
18+
import { postRefreshToken } from '@apis/student';
1919
// import { postTeacherRefreshToken } from '@apis/controller-teacher/auth';
2020
import { env } from '@utils';
2121

@@ -64,19 +64,15 @@ const reissueStudentToken = async () => {
6464

6565
const reissueTeacherToken = async () => {
6666
// let accessToken = getTeacherAccessToken();
67-
6867
// if (accessToken) {
6968
// return accessToken;
7069
// }
71-
7270
// const result = await postTeacherRefreshToken();
73-
7471
// if (!result.isSuccess || !result.data) {
7572
// console.warn('Teacher token refresh failed, clearing credentials.');
7673
// await clearAuthState();
7774
// return null;
7875
// }
79-
8076
// if (result.data?.token.accessToken) {
8177
// accessToken = result.data.token.accessToken;
8278
// await setTeacherAccessToken(accessToken);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { client } from '@apis';
2+
3+
const postPhoneResend = async (
4+
phone: string,
5+
purpose?: string,
6+
) => {
7+
return await client.POST('/api/auth/phone/resend', {
8+
body: {
9+
phone,
10+
purpose,
11+
},
12+
});
13+
};
14+
15+
export default postPhoneResend;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { client } from '@apis';
2+
3+
const postPhoneSend = async (
4+
phone: string,
5+
purpose?: string,
6+
) => {
7+
return await client.POST('/api/auth/phone/send', {
8+
body: {
9+
phone,
10+
purpose,
11+
},
12+
});
13+
};
14+
15+
export default postPhoneSend;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { client } from '@apis';
2+
3+
const postPhoneVerify = async (phone: string, code: string, purpose?: string) => {
4+
return await client.POST('/api/auth/phone/verify', {
5+
body: {
6+
phone,
7+
purpose,
8+
code,
9+
},
10+
});
11+
};
12+
13+
export default postPhoneVerify;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { client } from '@apis';
2+
3+
const deleteAccount = async () => {
4+
return await client.DELETE('/api/student/auth/quit');
5+
};
6+
7+
export default deleteAccount;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import deleteAccount from './deleteAccount';
2+
import postEmailSignup from './postEmailSignup';
3+
import postRefreshToken from './postRefreshToken';
4+
import postRegister from './postRegister';
5+
import postSocialLogin from './postSocialLogin';
6+
import useGetEmailExists from './useGetEmailExists';
7+
8+
export {
9+
deleteAccount,
10+
postEmailSignup,
11+
postRefreshToken,
12+
postRegister,
13+
postSocialLogin,
14+
useGetEmailExists,
15+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { client } from '@apis';
2+
import { components } from '@schema';
3+
4+
type StudentSignupReq = components['schemas']['StudentSignupReq'];
5+
const postEmailSignup = async (data: StudentSignupReq) => {
6+
try {
7+
const response = await client.POST('/api/student/auth/signup/local', {
8+
body: data,
9+
});
10+
return { isSuccess: true, data: response.data };
11+
} catch (error) {
12+
return { isSuccess: false, error: error };
13+
}
14+
};
15+
16+
export default postEmailSignup;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { env, getRefreshToken } from '@utils';
2+
3+
const postRefreshToken = async () => {
4+
try {
5+
const res = await fetch(`${env.apiBaseUrl}/api/student/auth/refresh`, {
6+
method: 'POST',
7+
headers: {
8+
'Content-Type': 'application/json',
9+
},
10+
body: JSON.stringify({
11+
refreshToken: getRefreshToken(),
12+
}),
13+
});
14+
if (!res.ok) throw new Error('Refresh failed');
15+
16+
const data = await res.json();
17+
return { isSuccess: true, data };
18+
} catch (e) {
19+
return { isSuccess: false, error: e };
20+
}
21+
};
22+
23+
export default postRefreshToken;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { client } from '@apis';
2+
import { components } from '@schema';
3+
4+
type StudentInitialRegisterReq = components['schemas']['StudentInitialRegisterDTO.Req'];
5+
const postRegister = async (data: StudentInitialRegisterReq) => {
6+
return await client.POST('/api/student/auth/register', {
7+
body: data,
8+
});
9+
};
10+
11+
export default postRegister;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { env } from '@utils';
2+
import { client } from '@apis';
3+
import { Platform } from 'react-native';
4+
5+
const getRedirectUri = () => {
6+
if (Platform.OS === 'web') {
7+
return `${window.location.origin}/auth/callback`;
8+
}
9+
10+
return env.authRedirectUri;
11+
};
12+
13+
const postSocialLogin = async (social: 'KAKAO' | 'GOOGLE') => {
14+
const response = await client.POST('/api/student/auth/login/social', {
15+
body: {
16+
provider: social,
17+
redirectUri: getRedirectUri(),
18+
},
19+
});
20+
21+
try {
22+
if (response && response.data) {
23+
return { isSuccess: true, loginUrl: response.data.loginUrl };
24+
} else {
25+
return { isSuccess: false, error: '데이터를 찾을 수 없습니다.' };
26+
}
27+
} catch (error) {
28+
return { isSuccess: false, error: error };
29+
}
30+
};
31+
32+
export default postSocialLogin;

0 commit comments

Comments
 (0)