가입 한 번이 회사를 하나 만들고 사장님이 그 회사의 직원이 됐다. 가입 폼은 "상호"를 묻고
에디터 헤더에는 "이름 · 회사명" 이 붙었다 — 쓰는 사람은 사장님 한 명인데.
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
141 lines
5.3 KiB
TypeScript
141 lines
5.3 KiB
TypeScript
import {useEffect, useState, type FormEvent} from 'react';
|
|
import {KeyRound, Loader2} from 'lucide-react';
|
|
import {AuthProvider, updateMe, useMe} from '@/api';
|
|
import {AppShell, PageContainer} from '@/components/layout/AppShell';
|
|
import {Button} from '@/components/ui/button';
|
|
import {Input} from '@/components/ui/input';
|
|
import {notify, notifyApiError} from '@/lib/notify';
|
|
import {toAuthUser, useAuthStore} from '@/stores/auth';
|
|
|
|
/**
|
|
* 내 정보 — `PATCH /v1/auth/me` 한 곳이 받는 것만 그린다.
|
|
*
|
|
* ★ 상호 칸은 없다. 회사(테넌트)를 걷어내면서(2026-09-08) 계정에 상호가 없어졌다 —
|
|
* 가게 이름은 사업장(place)이 갖는다.
|
|
* ★ 구글 계정에는 바꿀 비밀번호가 없다(서버가 ACCOUNT_PROVIDER_CONFLICT 로 막는다) —
|
|
* 입력칸 자체를 그리지 않는다.
|
|
*/
|
|
export function AccountPage() {
|
|
const {data, isLoading, refetch} = useMe();
|
|
const setUser = useAuthStore((s) => s.setUser);
|
|
|
|
const [name, setName] = useState('');
|
|
const [email, setEmail] = useState('');
|
|
const [contact, setContact] = useState('');
|
|
const [password, setPassword] = useState('');
|
|
const [isSaving, setIsSaving] = useState(false);
|
|
|
|
// 서버 값이 도착하면 한 번 채운다. 타이핑 중에 덮어쓰지 않게 응답이 바뀔 때만 돈다.
|
|
useEffect(() => {
|
|
if (!data) return;
|
|
setName(data.name ?? '');
|
|
setEmail(data.email ?? '');
|
|
setContact(data.contact_number ?? '');
|
|
}, [data]);
|
|
|
|
const isGoogle = data?.provider === AuthProvider.GOOGLE;
|
|
|
|
const handleSubmit = async (event: FormEvent) => {
|
|
event.preventDefault();
|
|
setIsSaving(true);
|
|
try {
|
|
const res = await updateMe({
|
|
name,
|
|
email,
|
|
contact_number: contact,
|
|
...(password ? {password} : {}),
|
|
});
|
|
if (!res.result?.success) {
|
|
notifyApiError({data: res}, '저장하지 못했습니다.');
|
|
return;
|
|
}
|
|
// 사이드바가 이름을 들고 있다 — 저장하고 스토어를 안 갱신하면 새로고침 전까지 옛 이름이다.
|
|
if (res.user_id && res.id) setUser(toAuthUser(res));
|
|
setPassword('');
|
|
notify.success('저장했습니다.');
|
|
await refetch();
|
|
} catch (error) {
|
|
notifyApiError(error, '저장하지 못했습니다.');
|
|
} finally {
|
|
setIsSaving(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<AppShell>
|
|
<PageContainer title="내 정보" description="이름·연락처와 로그인 정보를 관리합니다.">
|
|
{isLoading ? (
|
|
<div className="flex items-center justify-center py-20 text-muted-foreground">
|
|
<Loader2 className="size-5 animate-spin" />
|
|
</div>
|
|
) : (
|
|
<form onSubmit={handleSubmit} className="max-w-lg space-y-5">
|
|
<section className="space-y-3 rounded-xl border border-border bg-card p-5">
|
|
<Field label="로그인 아이디">
|
|
<p className="text-sm">{isGoogle ? (data?.email ?? '구글 계정') : (data?.id ?? '')}</p>
|
|
<p className="mt-0.5 text-xs text-muted-foreground">
|
|
{isGoogle ? '구글 계정으로 로그인합니다.' : '아이디는 바꿀 수 없습니다.'}
|
|
</p>
|
|
</Field>
|
|
</section>
|
|
|
|
<section className="space-y-4 rounded-xl border border-border bg-card p-5">
|
|
<Field label="이름">
|
|
<Input value={name} onChange={(e) => setName(e.target.value)} placeholder="홍길동" />
|
|
</Field>
|
|
<Field label="이메일">
|
|
<Input
|
|
type="email"
|
|
value={email}
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
placeholder="owner@example.com"
|
|
/>
|
|
</Field>
|
|
<Field label="연락처">
|
|
<Input value={contact} onChange={(e) => setContact(e.target.value)} placeholder="010-0000-0000" />
|
|
</Field>
|
|
</section>
|
|
|
|
{!isGoogle && (
|
|
<section className="space-y-4 rounded-xl border border-border bg-card p-5">
|
|
<Field label="새 비밀번호">
|
|
<Input
|
|
type="password"
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
placeholder="비우면 지금 비밀번호를 그대로 씁니다"
|
|
autoComplete="new-password"
|
|
/>
|
|
</Field>
|
|
</section>
|
|
)}
|
|
|
|
{isGoogle && (
|
|
<p className="flex items-center gap-1.5 text-xs text-muted-foreground">
|
|
<KeyRound className="size-3.5" />
|
|
구글 계정이라 비밀번호가 없습니다 — 비밀번호는 구글에서 관리합니다.
|
|
</p>
|
|
)}
|
|
|
|
<Button type="submit" variant="primary" isLoading={isSaving}>
|
|
저장
|
|
</Button>
|
|
</form>
|
|
)}
|
|
</PageContainer>
|
|
</AppShell>
|
|
);
|
|
}
|
|
|
|
function Field({label, children}: {label: string; children: React.ReactNode}) {
|
|
return (
|
|
<label className="block">
|
|
<span className="mb-1.5 block text-xs font-medium text-muted-foreground">{label}</span>
|
|
{children}
|
|
</label>
|
|
);
|
|
}
|
|
|
|
// 라우트 모듈은 default export 를 요구한다(routes.ts 가 이 파일을 가리킨다).
|
|
export default AccountPage;
|