login pinia

This commit is contained in:
2025-08-27 17:06:25 +09:00
parent ea3ec7de3b
commit ca44f8936a
3 changed files with 26 additions and 12 deletions

View File

@@ -29,7 +29,7 @@ export const useUserStore = defineStore("user", () => {
method: 'post',
body: { userId, password }
})
let mockUser;
if(data && data.value && data.value.success){
@@ -39,13 +39,9 @@ export const useUserStore = defineStore("user", () => {
}
user.value = mockUser;
token.value = "mock-token-" + Date.now();
// token.value = "mock-token-" + Date.now();
isLoggedIn.value = true;
// 로컬 스토리지에 저장
localStorage.setItem("user", JSON.stringify(mockUser));
localStorage.setItem("token", token.value);
return { success: true, user: mockUser };
} catch (error) {
console.error("로그인 실패:", error);
@@ -79,6 +75,14 @@ export const useUserStore = defineStore("user", () => {
}
};
const setToken = (accessToken : string) => {
token.value = accessToken;
}
const getToken = () => {
return token;
}
// 초기 인증 상태 확인
if (import.meta.client) {
checkAuth();
@@ -98,5 +102,7 @@ export const useUserStore = defineStore("user", () => {
login,
logout,
checkAuth,
setToken,
getToken
};
});