Merge branch 'iipbs/cs/dev'

This commit is contained in:
2026-05-28 16:10:20 +09:00
5 changed files with 47 additions and 26 deletions
+15 -8
View File
@@ -1,16 +1,17 @@
import { getRemainingMs } from "@common/auth";
import {
ENDPOINT,
CLAIM_NAME,
ACCESS_TOKEN,
AUTH_USER_ID,
CLAIM_NAME,
ENDPOINT,
} from "@/shared/config";
import type { ILogin } from "../model/auth-interface";
import { getRemainingMs } from "@common/auth";
import {
setToken,
clearAuthToken,
setToken,
setupRefreshTimer,
} from "../lib/token-manager";
import type { AuthPayload, AuthService } from "../model/auth-interface";
function resolveLoginError(message: string | undefined): string {
switch (message) {
@@ -27,7 +28,7 @@ function resolveLoginError(message: string | undefined): string {
}
}
export async function login(payload: ILogin): Promise<void> {
async function login(payload: AuthPayload): Promise<void> {
const response = await fetch(`/api/proxy${ENDPOINT.USER_SERVICE.LOGIN}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
@@ -56,7 +57,7 @@ export async function login(payload: ILogin): Promise<void> {
}
}
export async function silentRefresh(): Promise<void> {
async function silentRefresh(): Promise<void> {
console.log(`[silentRefresh] Called at ${new Date().toISOString()}`);
try {
const response = await fetch(
@@ -97,9 +98,15 @@ export async function silentRefresh(): Promise<void> {
}
}
export async function logout(): Promise<void> {
async function logout(): Promise<void> {
clearAuthToken();
if (typeof window !== "undefined") {
window.dispatchEvent(new CustomEvent("auth:logout"));
}
}
export const authService: AuthService = {
login,
silentRefresh,
logout,
};
+2 -2
View File
@@ -1,3 +1,3 @@
export { login, silentRefresh, logout } from "./api/auth-service";
export { authService } from "./api/auth-service";
export { AuthWrapper } from "./lib/auth-wrapper";
export { tokenManager } from "./lib/token-manager";
export { tokenManager } from "./lib/token-manager";
+15 -11
View File
@@ -2,20 +2,24 @@
import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { isAxiosError } from "axios";
import { client } from "@/shared/api";
import {
AUTH_LOGIN_REDIRECT_URL,
AUTH_USER_ID,
CLAIM_NAME,
ENDPOINT,
} from "@/shared/config";
import { useUserStore } from "@/shared/lib";
import type { IUserInfo } from "@/shared/store";
import { getRemainingMs } from "@common/auth";
import { isAtLoginRedirectUrl } from "@common/network";
import { client } from "@/shared/api";
import type { IUserInfo } from "@/shared/store";
import { useUserStore } from "@/shared/lib";
import {
ENDPOINT,
AUTH_USER_ID,
AUTH_LOGIN_REDIRECT_URL,
CLAIM_NAME,
} from "@/shared/config";
import { authService } from "../api/auth-service";
import { getToken, setupRefreshTimer } from "./token-manager";
import { silentRefresh } from "../api/auth-service";
const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
const router = useRouter();
@@ -31,7 +35,7 @@ const AuthWrapper = ({ children }: { children: React.ReactNode }) => {
console.log(
`[AuthWrapper] Refresh timer set: ${remainingMs}ms (${remainingMs / 1000}s)`,
);
setupRefreshTimer(silentRefresh, remainingMs);
setupRefreshTimer(authService.silentRefresh, remainingMs);
}
}
@@ -1,4 +1,10 @@
export interface ILogin {
export interface AuthPayload {
userId: string;
password: string;
}
export interface AuthService {
login(payload: AuthPayload): Promise<void>;
silentRefresh(): Promise<void>;
logout(): Promise<void>;
}
@@ -2,8 +2,10 @@
import { useState } from "react";
import Image from "next/image";
import { authService } from "@/entities/auth";
import { images } from "@common/assets";
import { login } from "@/entities/auth";
import "./login.css";
function LoginPage() {
@@ -18,7 +20,7 @@ function LoginPage() {
const password = formData.get("password") as string;
try {
await login({ userId, password });
await authService.login({ userId, password });
window.location.href = "/dashboard";
} catch (error) {
const message =
@@ -31,12 +33,14 @@ function LoginPage() {
<div className="login fx">
<div className="left_box fx">
<div className="text">
<h1>
<h1>
유역하수도통합플랫폼
<br />
<span>하수도플랫폼 통합관리(CMS)시스템</span>
</h1>
<p>유역하수도통합플랫폼 통합관리(CMS)시스템에 오신 것을 환영합니다.</p>
<p>
유역하수도통합플랫폼 통합관리(CMS)시스템에 오신 것을 환영합니다.
</p>
</div>
<div className="img">
<Image src={images.logo} width={229} height={46} alt="logo" />