가입 한 번이 회사를 하나 만들고 사장님이 그 회사의 직원이 됐다. 가입 폼은 "상호"를 묻고
에디터 헤더에는 "이름 · 회사명" 이 붙었다 — 쓰는 사람은 사장님 한 명인데.
negodata 보일러플레이트의 멀티테넌트 스코프 키를 그대로 물려받은 것이고,
DECISIONS.md 2절이 "대행사/운영사 단위로 그대로 쓴다" 로 유지 결정을 적어 뒀던 자리다.
- gmodel: `UserInfo.company_id` 삭제 — JWT 클레임에서도 사라진다. 스코프 키는 `user_id` 다
- place_crud·site_crud: WHERE 를 `places.owner_user_id` 로. `list_company_sites` → `list_owner_sites`
- place_service: **주인은 토큰이 정한다.** `Req_CreatePlace.owner_user_id` 를 없앴다 —
body 로 받으면 남의 계정을 적어 만들자마자 남의 목록에 넣을 수 있다.
실측: 기존 92건은 아무도 안 보내서 전부 NULL 이었고 스코프는 회사가 대신 하고 있었다
- 워커(collect·copy·build·vision): 잡 페이로드 키 `company_id` → `owner_user_id`.
잡이 세우는 `UserInfo.user_id` 는 이제 **사업장 주인**이다 — 예전엔 요청자·검증자·랜덤 uuid
순으로 채웠는데, 그 랜덤 uuid 가 스코프 키가 되는 순간 "남의 사업장" 이라 fact 조회가 0건이 된다
- auth: `Res_Me.company` · `Req_Signup.company_name` · `CompanyData` 삭제
- models·init.sql: `company.companies` 테이블 · `users.company_id` 삭제,
`places.owner_user_id` NOT NULL. 마이그레이션은 백필 → NOT NULL → DROP 순서다.
회사에 계정이 여럿이면 **가장 먼저 만든 계정**에게 몰고, 주인을 못 찾은 행은 지운다 —
스코프가 없으면 아무에게도 안 보이는 유령이다.
실측(로컬): place 92 → 91(고아 1건 삭제), `demoebf050` 56 · `test` 35
- 프론트: 가입 폼의 상호 칸, 내 정보의 상호 항목, 헤더의 "이름 · 회사명" 삭제
- 테스트: `company_id`/`other_company_id` 픽스처 → `owner_id` 하나.
격리는 `auth_headers("o2")` 를 한 번 더 부르면 그게 남이다
남긴 것 — DB 스키마 이름 `company` 는 그대로다. rename 은 모든 모델의 `__table_args__` 를
건드려야 해서 이번 변경에 섞지 않았다.
검증: 전체 568 passed(실패 1건은 HEAD 에서도 깨지는 레이트리밋 테스트) ·
프론트 tsc+eslint 통과 · 실제 API 로 가입→사업장→목록→격리→발행 한 바퀴
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QLWEFx4X3XRmKewUKjJWow
212 lines
7.7 KiB
TypeScript
212 lines
7.7 KiB
TypeScript
import {useState, type FormEvent} from 'react';
|
|
import {Link, Navigate, useNavigate} from 'react-router';
|
|
import {UserPlus} from 'lucide-react';
|
|
import {googleLogin, signup} from '@/api';
|
|
import {GoogleSignInButton} from '@/components/auth/GoogleSignInButton';
|
|
import {Button} from '@/components/ui/button';
|
|
import {Input} from '@/components/ui/input';
|
|
import {isGoogleLoginEnabled} from '@/lib/googleIdentity';
|
|
import {notify, notifyApiError} from '@/lib/notify';
|
|
import {establishSession} from '@/lib/session';
|
|
import {useAuthStore} from '@/stores/auth';
|
|
|
|
/**
|
|
* 회원가입. 가입 = **새 회사(테넌트) 1개 + 그 회사의 첫 계정 1개** 다(백엔드 auth_service.signup).
|
|
*
|
|
* ★ 여기 검사는 서버 규칙(services/auth_service.py 의 _LOGIN_ID_RE·_MIN_PASSWORD_LEN)의 사본이다.
|
|
* 두 벌이라 어긋날 수 있지만, 서버가 마지막 방어선이고 여기는 "제출 전에 알려주는" 역할이다.
|
|
* 규칙을 바꾸면 두 곳을 같이 고친다.
|
|
*/
|
|
const ID_RE = /^[a-zA-Z][a-zA-Z0-9._-]{3,19}$/;
|
|
const EMAIL_RE = /^[^@\s]+@[^@\s]+\.[^@\s]+$/;
|
|
const MIN_PASSWORD_LEN = 8;
|
|
|
|
export function SignupPage() {
|
|
const navigate = useNavigate();
|
|
const user = useAuthStore((s) => s.user);
|
|
|
|
const [form, setForm] = useState({
|
|
id: '',
|
|
password: '',
|
|
passwordConfirm: '',
|
|
name: '',
|
|
email: '',
|
|
});
|
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
|
|
if (user) return <Navigate to="/sites" replace />;
|
|
|
|
const set = (key: keyof typeof form) => (e: {target: {value: string}}) =>
|
|
setForm((prev) => ({...prev, [key]: e.target.value}));
|
|
|
|
const validate = (): string | null => {
|
|
if (!ID_RE.test(form.id)) return '아이디는 영문으로 시작하는 4~20자입니다(영문·숫자·. _ - 사용).';
|
|
if (form.password.length < MIN_PASSWORD_LEN) return `비밀번호는 ${MIN_PASSWORD_LEN}자 이상이어야 합니다.`;
|
|
if (form.password !== form.passwordConfirm) return '비밀번호가 서로 다릅니다.';
|
|
if (!EMAIL_RE.test(form.email)) return '이메일 형식을 확인해 주세요.';
|
|
return null;
|
|
};
|
|
|
|
const handleSubmit = async (event: FormEvent) => {
|
|
event.preventDefault();
|
|
const invalid = validate();
|
|
if (invalid) {
|
|
notify.error(invalid);
|
|
return;
|
|
}
|
|
|
|
setIsSubmitting(true);
|
|
try {
|
|
const res = await signup({
|
|
id: form.id.trim(),
|
|
password: form.password,
|
|
name: form.name.trim() || null,
|
|
email: form.email.trim(),
|
|
});
|
|
if (res.result?.success === false) {
|
|
notifyApiError({data: res}, '가입하지 못했습니다.');
|
|
return;
|
|
}
|
|
// 가입 응답에 토큰이 실려 온다 — 방금 정한 비밀번호를 다시 치게 하지 않는다.
|
|
if (!(await establishSession(res, form.id.trim()))) {
|
|
notifyApiError({data: res}, '가입은 됐지만 로그인 토큰이 오지 않았습니다. 다시 로그인해 주세요.');
|
|
navigate('/login', {replace: true});
|
|
return;
|
|
}
|
|
notify.success('가입이 완료되었습니다.');
|
|
navigate('/sites', {replace: true});
|
|
} catch (error) {
|
|
notifyApiError(error, '가입하지 못했습니다.');
|
|
} finally {
|
|
setIsSubmitting(false);
|
|
}
|
|
};
|
|
|
|
// 구글은 가입과 로그인이 같은 동작이다 — 처음 온 계정이면 백엔드가 그 자리에서 만든다.
|
|
const handleGoogle = async (credential: string) => {
|
|
setIsSubmitting(true);
|
|
try {
|
|
const res = await googleLogin({credential});
|
|
if (res.result?.success === false) {
|
|
notifyApiError({data: res}, '구글로 가입하지 못했습니다.');
|
|
return;
|
|
}
|
|
if (!(await establishSession(res, ''))) {
|
|
notifyApiError({data: res}, '로그인 응답에 토큰이 없습니다.');
|
|
return;
|
|
}
|
|
navigate('/sites', {replace: true});
|
|
} catch (error) {
|
|
notifyApiError(error, '구글로 가입하지 못했습니다.');
|
|
} finally {
|
|
setIsSubmitting(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="flex min-h-screen items-center justify-center bg-muted/30 px-4 py-8">
|
|
<form
|
|
onSubmit={handleSubmit}
|
|
className="w-full max-w-sm space-y-4 rounded-2xl border border-border bg-card p-7"
|
|
>
|
|
<div className="space-y-1 text-center">
|
|
{/* 로고는 어디서든 랜딩으로 돌아가는 문이다. */}
|
|
<Link to="/" className="mx-auto mb-3 block w-fit">
|
|
<img src="/brand/web4ai-wordmark.svg" alt="Web4Ai" className="h-9 w-auto" />
|
|
</Link>
|
|
<h1 className="text-sm font-medium text-muted-foreground">회원가입</h1>
|
|
<p className="text-xs text-muted-foreground">내 가게 사이트를 만들려면 계정이 필요합니다.</p>
|
|
</div>
|
|
|
|
<div className="space-y-3">
|
|
<div>
|
|
<label htmlFor="signup-id" className="mb-1.5 block text-xs font-semibold">
|
|
아이디
|
|
</label>
|
|
<Input
|
|
id="signup-id"
|
|
value={form.id}
|
|
onChange={set('id')}
|
|
autoComplete="username"
|
|
placeholder="영문으로 시작하는 4~20자"
|
|
required
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label htmlFor="signup-pw" className="mb-1.5 block text-xs font-semibold">
|
|
비밀번호
|
|
</label>
|
|
<Input
|
|
id="signup-pw"
|
|
type="password"
|
|
value={form.password}
|
|
onChange={set('password')}
|
|
autoComplete="new-password"
|
|
placeholder={`${MIN_PASSWORD_LEN}자 이상`}
|
|
required
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label htmlFor="signup-pw2" className="mb-1.5 block text-xs font-semibold">
|
|
비밀번호 확인
|
|
</label>
|
|
<Input
|
|
id="signup-pw2"
|
|
type="password"
|
|
value={form.passwordConfirm}
|
|
onChange={set('passwordConfirm')}
|
|
autoComplete="new-password"
|
|
required
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label htmlFor="signup-name" className="mb-1.5 block text-xs font-semibold">
|
|
이름
|
|
</label>
|
|
<Input id="signup-name" value={form.name} onChange={set('name')} autoComplete="name" />
|
|
</div>
|
|
<div>
|
|
<label htmlFor="signup-email" className="mb-1.5 block text-xs font-semibold">
|
|
이메일
|
|
</label>
|
|
<Input
|
|
id="signup-email"
|
|
type="email"
|
|
value={form.email}
|
|
onChange={set('email')}
|
|
autoComplete="email"
|
|
required
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<Button type="submit" variant="primary" className="w-full" isLoading={isSubmitting}>
|
|
<UserPlus />
|
|
<span>가입하기</span>
|
|
</Button>
|
|
|
|
{isGoogleLoginEnabled() && (
|
|
<>
|
|
<div className="flex items-center gap-2">
|
|
<span className="h-px flex-1 bg-border" />
|
|
<span className="text-[11px] text-muted-foreground">또는</span>
|
|
<span className="h-px flex-1 bg-border" />
|
|
</div>
|
|
<GoogleSignInButton onCredential={handleGoogle} text="signup_with" />
|
|
</>
|
|
)}
|
|
|
|
<p className="text-center text-[11px] leading-relaxed text-muted-foreground">
|
|
이미 계정이 있으신가요?{' '}
|
|
<Link to="/login" className="font-medium text-primary underline-offset-2 hover:underline">
|
|
로그인
|
|
</Link>
|
|
</p>
|
|
</form>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// 라우트 모듈은 default export 를 요구한다(routes.ts 가 이 파일을 가리킨다).
|
|
export default SignupPage;
|