-
Notifications
You must be signed in to change notification settings - Fork 0
CLAP-205 로그인 관련 API 연결 #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 24 commits
09dd262
89d9fa7
0f024ee
d8712e2
c3ae5cd
61c54f0
e512e46
45d3815
61df8a1
11462ed
6a6b4a6
61ed646
d1a8a41
65b0f37
cd970aa
8c202cf
281050c
9f952ae
f97d35b
c49d1fb
d6b475b
81bb0ca
6404730
f9d5023
1bb1826
9e76611
6ccd304
de257f7
008fa11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { axiosInstance } from '@/utils/axios' | ||
| import Cookies from 'js-cookie' | ||
|
|
||
| export const postLogin = async (nickname: string, password: string) => { | ||
| const body = { | ||
| nickname: nickname, | ||
| password: password | ||
| } | ||
| const sessionIdValue = '123' | ||
| try { | ||
BaekJiyeon02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const response = await axiosInstance.post('/api/auths/login', body, { | ||
| headers: { | ||
| sessionId: sessionIdValue | ||
| } | ||
| }) | ||
BaekJiyeon02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Cookies.set('accessToken', response.data.accessToken, { | ||
|
||
| path: '/', | ||
| sameSite: 'strict' | ||
| }) | ||
|
|
||
| return response.data | ||
| } catch (error) { | ||
| console.error('로그인 오류:', error) | ||
| throw error | ||
| } | ||
| } | ||
|
|
||
| export const patchPassword = async (password: string) => { | ||
| const accessToken = Cookies.get('accessToken') | ||
|
|
||
| if (!accessToken) { | ||
| console.error('Access token is missing') | ||
| return | ||
| } | ||
|
|
||
| try { | ||
| const response = await axiosInstance.patch('/api/members/password', password, { | ||
| headers: { | ||
| Authorization: `Bearer ${accessToken}` | ||
| } | ||
| }) | ||
| return response.data | ||
| } catch (error) { | ||
| console.log('api error:', error) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { defineStore } from 'pinia' | ||
| import { axiosInstance } from '@/utils/axios' | ||
| import { ref } from 'vue' | ||
| import type { User } from '@/types/auth' | ||
| import Cookies from 'js-cookie' | ||
|
|
||
| export const useMemberStore = defineStore('memberInfo', () => { | ||
| const info = ref<User>({ | ||
| memberId: 0, | ||
| memberName: '', | ||
| nickname: '', | ||
| imageUrl: '', | ||
| memberRole: '', | ||
| memberStatus: '' | ||
| }) | ||
|
|
||
| async function updateMemberInfoWithToken() { | ||
| try { | ||
| const accessToken = Cookies.get('accessToken') | ||
|
|
||
| if (!accessToken) { | ||
| console.error('Access token error') | ||
| return | ||
| } | ||
|
|
||
| const response = await axiosInstance.get('/api/members/info', { | ||
BaekJiyeon02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| headers: { | ||
| Authorization: `Bearer ${accessToken}` | ||
| } | ||
| }) | ||
|
|
||
| console.log('API Response:', response.data) | ||
| updateMemberInfo(response.data) | ||
| } catch (error) { | ||
| console.error('updata error:', error) | ||
| } | ||
| } | ||
|
|
||
| function updateMemberInfo(responseData: any) { | ||
| info.value = { | ||
| memberId: 0, | ||
BaekJiyeon02 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| memberName: responseData.name || '', | ||
| nickname: responseData.nicknanme || '', | ||
| imageUrl: responseData.profileImageUrl || '', | ||
| memberRole: responseData.role || '', | ||
| memberStatus: '' | ||
| } | ||
|
|
||
| console.log('Updated member info:', info.value) | ||
| } | ||
|
|
||
| return { | ||
| info, | ||
| updateMemberInfo, | ||
| updateMemberInfoWithToken | ||
| } | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.