rename: 폴더 이동 및 파일명 수정
This commit is contained in:
@@ -17,7 +17,7 @@ export async function POST(
|
||||
|
||||
const headers: Record<string, string> = {
|
||||
"Content-Type": "application/json",
|
||||
"X-Site-Id": SITE_ID ?? "",
|
||||
"X-Site-Id": SITE_ID,
|
||||
};
|
||||
|
||||
const cookieStore = await cookies();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import "./styles/base.css";
|
||||
import "./styles/components.css";
|
||||
import { CookieProvider, QueryProvider } from "@/shared/providers";
|
||||
import { CookieProvider, QueryProvider } from "@/shared/provider";
|
||||
|
||||
const App = ({ children }: Readonly<{ children: React.ReactNode }>) => {
|
||||
return (
|
||||
|
||||
+1
-1
@@ -1,8 +1,8 @@
|
||||
import { AxiosError } from "axios";
|
||||
import { ENDPOINT, JWT_EXPIRATION_TIME } from "@/shared/config/api";
|
||||
import { ACCESS_TOKEN, AUTH_USER_ID, CLAIM_NAME } from "@/shared/config/env";
|
||||
import type { LoginService, ILogin } from "../model/login-interface";
|
||||
import { tokenManager } from "../lib/token-manager";
|
||||
import type { LoginService, ILogin } from "../model/login";
|
||||
|
||||
export class LoginApiService implements LoginService {
|
||||
private static instance: LoginApiService;
|
||||
@@ -0,0 +1 @@
|
||||
export { LoginApi } from "./api/login-service";
|
||||
+12
-4
@@ -1,5 +1,5 @@
|
||||
import { AUTH_USER_ID, CLAIM_NAME } from "@/shared/config/env";
|
||||
import { setToken, removeToken } from "@/shared/lib/cookie";
|
||||
import { getCookie, setCookie, removeCookie } from "@/shared/lib/cookie";
|
||||
|
||||
export class TokenManager {
|
||||
private static instance: TokenManager;
|
||||
@@ -14,13 +14,21 @@ export class TokenManager {
|
||||
return TokenManager.instance;
|
||||
}
|
||||
|
||||
public getToken(key: string): string | undefined {
|
||||
return getCookie(key);
|
||||
}
|
||||
|
||||
public setToken(key: string, value: string): void {
|
||||
setToken(key, value, {
|
||||
setCookie(key, value, {
|
||||
secure: window.location.protocol === "https:",
|
||||
sameSite: "lax",
|
||||
});
|
||||
}
|
||||
|
||||
public removeToken(key: string): void {
|
||||
removeCookie(key);
|
||||
}
|
||||
|
||||
public setupRefreshTimer(
|
||||
callback: () => Promise<void>,
|
||||
expirationTime: number,
|
||||
@@ -43,8 +51,8 @@ export class TokenManager {
|
||||
this.refreshTimer = null;
|
||||
}
|
||||
|
||||
removeToken(CLAIM_NAME);
|
||||
removeToken(AUTH_USER_ID);
|
||||
this.removeToken(CLAIM_NAME);
|
||||
this.removeToken(AUTH_USER_ID);
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -5,4 +5,5 @@ export interface ILogin {
|
||||
|
||||
export interface LoginService {
|
||||
login(payload: ILogin): Promise<void>;
|
||||
silentRefresh(): Promise<void>;
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { UserApi } from "../api/user-service";
|
||||
import { useCookie } from "@/shared/providers";
|
||||
import { ENDPOINT } from "@/shared/config/api";
|
||||
import { AUTH_USER_ID } from "@/shared/config/env";
|
||||
import { useCookie } from "@/shared/provider";
|
||||
import { UserApi } from "../api/user-service";
|
||||
|
||||
const useUser = () => {
|
||||
const { getToken } = useCookie();
|
||||
const { getCookie } = useCookie();
|
||||
const { data } = useQuery({
|
||||
queryKey: [ENDPOINT.USER_SERVICE.USERS],
|
||||
queryFn: () =>
|
||||
UserApi.userInfo({
|
||||
userUniqId: getToken(AUTH_USER_ID) ?? "",
|
||||
userUniqId: getCookie(AUTH_USER_ID) ?? "",
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import Image from "next/image";
|
||||
import { images } from "@common/assets";
|
||||
import { LoginApi } from "../api/login";
|
||||
import { LoginApi } from "@/entities/auth/login";
|
||||
import "./login.css";
|
||||
|
||||
function LoginPage() {
|
||||
|
||||
@@ -12,7 +12,7 @@ export function getCookie(name: string): string | undefined {
|
||||
export function setCookie(
|
||||
name: string,
|
||||
value: string,
|
||||
options: Cookies.CookieAttributes,
|
||||
options?: Cookies.CookieAttributes,
|
||||
): void {
|
||||
if (typeof window === "undefined") {
|
||||
return;
|
||||
@@ -22,29 +22,10 @@ export function setCookie(
|
||||
|
||||
export function removeCookie(
|
||||
name: string,
|
||||
options: Cookies.CookieAttributes,
|
||||
options?: Cookies.CookieAttributes,
|
||||
): void {
|
||||
if (typeof window === "undefined") {
|
||||
return;
|
||||
}
|
||||
Cookies.remove(name, options);
|
||||
}
|
||||
|
||||
export function getToken(key: string): string | undefined {
|
||||
return getCookie(key);
|
||||
}
|
||||
|
||||
export function setToken(
|
||||
key: string,
|
||||
token: string,
|
||||
options: Cookies.CookieAttributes,
|
||||
): void {
|
||||
setCookie(key, token, {
|
||||
...options,
|
||||
path: "/",
|
||||
});
|
||||
}
|
||||
|
||||
export function removeToken(key: string): void {
|
||||
removeCookie(key, { path: "/" });
|
||||
}
|
||||
|
||||
+1
-19
@@ -1,24 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
getCookie,
|
||||
setCookie,
|
||||
removeCookie,
|
||||
getToken,
|
||||
setToken,
|
||||
removeToken,
|
||||
} from "../../lib/cookie";
|
||||
|
||||
import { createContext, useContext } from "react";
|
||||
import { getCookie, setCookie, removeCookie } from "../../lib/cookie";
|
||||
|
||||
export interface CookieContextType {
|
||||
getToken: (key: string) => string | undefined;
|
||||
setToken: (
|
||||
key: string,
|
||||
token: string,
|
||||
options: Cookies.CookieAttributes,
|
||||
) => void;
|
||||
removeToken: (key: string) => void;
|
||||
getCookie: (name: string) => string | undefined;
|
||||
setCookie: (
|
||||
name: string,
|
||||
@@ -32,9 +17,6 @@ export const CookieContext = createContext<CookieContextType | null>(null);
|
||||
|
||||
export function CookieProvider({ children }: { children: React.ReactNode }) {
|
||||
const cookieContextValue: CookieContextType = {
|
||||
getToken,
|
||||
setToken,
|
||||
removeToken,
|
||||
getCookie,
|
||||
setCookie,
|
||||
removeCookie,
|
||||
@@ -3,4 +3,4 @@ export {
|
||||
CookieProvider,
|
||||
useCookie,
|
||||
} from "./cookie/cookie-provider";
|
||||
export { QueryProvider } from "./query/query-client";
|
||||
export { QueryProvider } from "./query/query-provider";
|
||||
Reference in New Issue
Block a user