Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added frontend/public/brand/google-g.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions frontend/src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@
/* 스크롤바 */
--scrollbar-thumb: #e5d5c6;
--scrollbar-thumb-hover: #fdba74;

/* 소셜 로그인 버튼. 각 회사 디자인 가이드의 고정 값이라 서비스 색으로 바꾸지 않는다
카카오: developers.kakao.com/docs/latest/ko/kakaologin/design-guide
구글: developers.google.com/identity/branding-guidelines (Light 테마) */
--kakao-container: #fee500;
--kakao-symbol: #000000;
--kakao-label: rgb(0 0 0 / 0.85);
--google-fill: #ffffff;
--google-stroke: #747775;
--google-label: #1f1f1f;
}

@theme inline {
Expand Down Expand Up @@ -168,6 +178,13 @@
--color-map-closed-light: var(--map-closed-light);
--color-map-closed-stroke: var(--map-closed-stroke);

--color-kakao-container: var(--kakao-container);
--color-kakao-symbol: var(--kakao-symbol);
--color-kakao-label: var(--kakao-label);
--color-google-fill: var(--google-fill);
--color-google-stroke: var(--google-stroke);
--color-google-label: var(--google-label);

--shadow-soft: 0 1px 2px rgb(41 31 27 / 0.04), 0 4px 16px rgb(41 31 27 / 0.06);
--shadow-lifted: 0 2px 4px rgb(41 31 27 / 0.05), 0 12px 32px rgb(41 31 27 / 0.1);
}
Expand Down
10 changes: 6 additions & 4 deletions frontend/src/components/about-data/account-section.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use client";

import { CircleCheck, Hourglass, LogIn, LogOut, UserX } from "lucide-react";
import Link from "next/link";
import { useEffect, useState } from "react";

import { useRequireLogin } from "@/components/auth/login-required";
import { ErrorNotice } from "@/components/feedback/error-notice";
import { Skeleton } from "@/components/ui/skeleton";
import { toErrorKind, type ApiErrorKind } from "@/lib/api/errors";
Expand Down Expand Up @@ -79,6 +79,7 @@ export function AccountSection({
onWithdrawn?: () => void;
}) {
const session = useSessionStatus();
const { openLogin } = useRequireLogin();
const [me, setMe] = useState<Me | null>(null);
const [meError, setMeError] = useState<ApiErrorKind | null>(null);
const [reload, setReload] = useState(0);
Expand Down Expand Up @@ -143,13 +144,14 @@ export function AccountSection({
<p className="text-sm text-ink-500">
로그인하면 진단·계약 자료를 계정에 보관하고 로그아웃·데이터 삭제·회원 탈퇴를 할 수 있어요.
</p>
<Link
href="/login"
<button
type="button"
onClick={() => openLogin()}
className="inline-flex min-h-12 items-center justify-center gap-1.5 rounded-2xl bg-primary px-5 font-extrabold text-primary-foreground transition-colors hover:bg-primary-hover"
>
<LogIn className="size-4" aria-hidden="true" />
로그인
</Link>
</button>
</>
) : (
<>
Expand Down
199 changes: 199 additions & 0 deletions frontend/src/components/auth/login-panel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
"use client";

import Link from "next/link";
import { CircleAlert } from "lucide-react";
import { useRouter } from "next/navigation";
import { useId, useState, useSyncExternalStore } from "react";

import { SocialLoginButton } from "@/components/auth/social-login-button";
import { SampleDataNotice } from "@/components/feedback/sample-data";
import { Checkbox } from "@/components/ui/checkbox";
import { Label } from "@/components/ui/label";
import { completeLogin, prepareLogin } from "@/lib/api/auth";
import { isMockMode } from "@/lib/api/mock";
import { callApp, getAppInfo, isInApp } from "@/lib/bridge";
import { LOGIN_ERROR_COPY, parseCallbackQuery, type LoginError, type LoginProvider } from "@/lib/auth";
import { takeLoginReturn } from "@/lib/return-to";
import {
forgetTermsAgreement,
hasAgreedTerms,
PRIVACY_HREF,
rememberTermsAgreement,
TERMS_HREF,
TERMS_VERSION,
} from "@/lib/terms";

const noSubscribe = () => () => {};

type LoginPanelProps = {
/** 로그인에 실패하고 돌아온 경우의 오류 (로그인 화면의 주소 쿼리) */
initialError?: LoginError | null;
/** 앱에서 로그인을 마쳐 화면을 옮긴 뒤 부른다. 하단 로그인 창을 닫는 데 쓴다 */
onDone?: () => void;
};

/**
* 로그인 본문. 약관 동의와 만 14세 이상 확인 뒤 구글·카카오 로그인을 시작한다 (스펙 R1·R4·R8).
* 로그인 화면(S13)과 하단 로그인 창이 함께 쓴다. 돌아갈 주소는 여는 쪽이 saveLoginReturn 으로 먼저 기억한다.
*/
export function LoginPanel({ initialError = null, onDone }: LoginPanelProps) {
const termsId = useId();
const ageId = useId();
const [agreed, setAgreed] = useState(false);
const [over14, setOver14] = useState(false);
const [pending, setPending] = useState<LoginProvider | null>(null);
const [localError, setLocalError] = useState<LoginError | null>(null);
const [dismissed, setDismissed] = useState(false);
const error = localError ?? (dismissed ? null : initialError);
const router = useRouter();

// 이 브라우저에서 같은 버전에 동의했으면 다시 묻지 않는다 (API 명세서 A26)
const remembered = useSyncExternalStore(
noSubscribe,
() => hasAgreedTerms(),
() => false,
);
const consented = remembered || (agreed && over14);
const ready = consented && pending === null;

async function start(provider: LoginProvider) {
if (!consented) return;
rememberTermsAgreement();
setPending(provider);
setLocalError(null);
setDismissed(true);
const inApp = isInApp();
if (inApp && (getAppInfo()?.bridgeVersion ?? 0) < 2) {
setPending(null);
setLocalError("app_update_required");
return;
}
const url = await prepareLogin(provider, inApp ? "app" : "web");
if (!url) {
setPending(null);
setLocalError("invalid_request");
return;
}
if (!inApp || isMockMode()) {
window.location.assign(url);
return;
}

try {
const result = await callApp(
"openAuthSession",
{ url, returnUrl: "axservice://auth/callback", timeoutMs: 180_000 },
{ timeoutMs: 180_000 },
);
if (result.type !== "success") {
setLocalError(result.type === "timeout" ? "browser_timeout" : "cancelled");
setPending(null);
return;
}

const callback = new URL(result.url);
if (`${callback.protocol}//${callback.host}${callback.pathname}` !== "axservice://auth/callback") {
throw new Error("허용하지 않는 로그인 복귀 주소입니다.");
}
const callbackResult = parseCallbackQuery(callback.searchParams);
if (callbackResult.kind === "error") {
if (callbackResult.error === "terms_outdated") forgetTermsAgreement();
setLocalError(callbackResult.error);
setPending(null);
return;
}
const outcome = await completeLogin(callbackResult.code);
// 웹의 콜백 화면(auth-callback-view)과 같이 기억해 둔 화면으로 돌아간다
if (outcome.ok) {
router.replace(takeLoginReturn());
onDone?.();
} else {
setLocalError(outcome.error);
setPending(null);
}
} catch {
setLocalError("exchange_failed");
setPending(null);
}
}

const copy = error ? LOGIN_ERROR_COPY[error] : null;

return (
<div className="flex flex-col gap-4">
{isMockMode() && (
<SampleDataNotice>예시 모드라 구글·카카오로 가지 않고 예시 계정으로 로그인해요.</SampleDataNotice>
)}

{copy && (
<div role="alert" className="flex gap-2 rounded-xl border border-destructive/30 bg-card p-4">
<CircleAlert className="mt-0.5 size-5 shrink-0 text-destructive" aria-hidden="true" />
<div className="flex flex-col gap-1">
<p className="font-bold text-foreground">{copy.title}</p>
<p className="text-sm text-muted-foreground">{copy.description}</p>
</div>
</div>
)}

{remembered ? (
<p className="rounded-xl border bg-card p-4 text-sm text-muted-foreground">
이 브라우저에서 이용약관·개인정보 처리방침(버전 {TERMS_VERSION})에 동의하고 만 14세 이상임을 확인했어요.{" "}
<Link href={TERMS_HREF} className="text-primary underline underline-offset-2">
이용약관 보기
</Link>
</p>
) : (
<fieldset className="flex flex-col gap-1 rounded-xl border bg-card p-2">
<legend className="sr-only">로그인 전 확인</legend>
<div className="flex min-h-11 items-start gap-3 px-2 py-2">
<Checkbox
id={termsId}
checked={agreed}
onCheckedChange={(value) => setAgreed(value === true)}
className="mt-0.5"
/>
<div className="flex flex-col gap-1">
<Label htmlFor={termsId} className="text-base leading-snug font-semibold">
이용약관과 개인정보 처리방침에 동의해요 (필수)
</Label>
<p className="flex gap-3 text-sm">
<Link href={TERMS_HREF} className="text-primary underline underline-offset-2">
이용약관 보기
</Link>
<Link href={PRIVACY_HREF} className="text-primary underline underline-offset-2">
개인정보 처리방침 보기
</Link>
</p>
</div>
</div>
<div className="flex min-h-11 items-start gap-3 px-2 py-2">
<Checkbox
id={ageId}
checked={over14}
onCheckedChange={(value) => setOver14(value === true)}
className="mt-0.5"
/>
<Label htmlFor={ageId} className="text-base leading-snug font-semibold">
만 14세 이상이에요 (필수)
</Label>
</div>
</fieldset>
)}

<div className="flex flex-col gap-2">
{!consented ? (
<p className="text-center text-sm text-muted-foreground">두 항목을 모두 확인하면 로그인할 수 있어요.</p>
) : null}
{(["kakao", "google"] as const).map((provider) => (
<SocialLoginButton
key={provider}
provider={provider}
pending={pending === provider}
disabled={!ready}
onClick={() => void start(provider)}
/>
))}
</div>
</div>
);
}
Loading