[feat] solution/backend,frontend: id/pw 가입 · 구글 로그인 — 계정을 만들 길이 없던 걸 연다
계정 생성 API 가 아예 없었다(그동안 users 를 손으로 INSERT 했다). 로그인 화면은 있는데 그 뒤에 설 계정을 만들 방법이 제품에 없는 상태였다. - auth_service.signup: 가입 = **새 회사(테넌트) 1개 + 첫 계정 1개**. users.company_id 가 NOT NULL 이고 모든 도메인이 company 로 스코프돼서, 회사 없는 계정은 아무것도 못 만든다 - services/external/google_identity: 구글 ID 토큰의 서명·iss·만료에 더해 **aud(우리 client_id)와 email_verified 를 본다.** aud 검사가 빠지면 남의 앱에 발급된 '진짜' 구글 토큰으로 우리 계정에 들어온다 — 서명도 발급자도 전부 맞으므로 다른 검사로는 안 걸린다 - users.provider/provider_uid 추가, password NULL 허용, id 20→64자(google_<sub> 가 20자를 넘는다). provider 에 server_default 를 같이 준 이유: ORM default 는 raw INSERT(테스트 시드)에 안 먹어서 NOT NULL 컬럼이면 그 경로가 통째로 깨진다 - attempt_login: 소셜 계정을 먼저 끊는다. 안 끊으면 bcrypt 가 None 해시를 만나 500 이다 - 같은 이메일이라도 id/pw 계정과 구글 계정을 **잇지 않는다.** 이으면 계정 선점이다 — 남의 이메일로 먼저 만들어 둔 계정에 그 사람의 구글 로그인이 들어간다 → DECISIONS 1-5 - LoginPage 는 admin 과 공유라 selfServe 로 갈랐다. admin 은 가입 링크도 구글 버튼도 안 뜬다 (admin 라우터에 /signup 이 없어 404 가 난다) - GOOGLE_CLIENT_ID 는 루트 .env 한 곳. compose 가 VITE_GOOGLE_CLIENT_ID 로 흘려보낸다 — 두 곳에 적으면 백엔드 aud 대조와 화면 버튼이 조용히 갈라진다 ★ 이미 도는 DB 는 init.sql 을 다시 적용해야 한다(말미 ALTER 섹션). pytest: auth 13건 + 구글 토큰 검증 8건(진짜 RSA 서명으로 aud·iss·만료·email_verified·변조 거절 확인) 통과. 전체 527 passed / 8 failed(전부 기존 실패, 인증과 무관). tsc·eslint·vite build 통과.
This commit is contained in:
1 parent
c250b656fd
commit
48109fdc99
37 files changed
+1554
-62
No files matched your search
@@ -25,7 +25,9 @@ import type {
|
||||
|
||||
import type {
|
||||
HTTPValidationError,
|
||||
ReqGoogleLogin,
|
||||
ReqLogin,
|
||||
ReqSignup,
|
||||
ReqUpdateMe,
|
||||
ResLogin,
|
||||
ResMe,
|
||||
@@ -105,6 +107,136 @@ export const useLogin = <TError = void | HTTPValidationError,
|
||||
return useMutation(mutationOptions, queryClient);
|
||||
}
|
||||
/**
|
||||
* id/pw 로 가입한다. 회사(테넌트) 1개가 함께 생기고, 성공하면 곧바로 로그인 토큰을 발급한다.
|
||||
* @summary 회원가입
|
||||
*/
|
||||
export const signup = (
|
||||
reqSignup: ReqSignup,
|
||||
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
||||
) => {
|
||||
|
||||
|
||||
return customFetch<ResLogin>(
|
||||
{url: `/v1/auth/signup`, method: 'POST',
|
||||
headers: {'Content-Type': 'application/json', },
|
||||
data: reqSignup, signal
|
||||
},
|
||||
options);
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const getSignupMutationOptions = <TError = void | HTTPValidationError,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof signup>>, TError,{data: ReqSignup}, TContext>, request?: SecondParameter<typeof customFetch>}
|
||||
): UseMutationOptions<Awaited<ReturnType<typeof signup>>, TError,{data: ReqSignup}, TContext> => {
|
||||
|
||||
const mutationKey = ['signup'];
|
||||
const {mutation: mutationOptions, request: requestOptions} = options ?
|
||||
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
||||
options
|
||||
: {...options, mutation: {...options.mutation, mutationKey}}
|
||||
: {mutation: { mutationKey, }, request: undefined};
|
||||
|
||||
|
||||
|
||||
|
||||
const mutationFn: MutationFunction<Awaited<ReturnType<typeof signup>>, {data: ReqSignup}> = (props) => {
|
||||
const {data} = props ?? {};
|
||||
|
||||
return signup(data,requestOptions)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return { mutationFn, ...mutationOptions }}
|
||||
|
||||
export type SignupMutationResult = NonNullable<Awaited<ReturnType<typeof signup>>>
|
||||
export type SignupMutationBody = ReqSignup
|
||||
export type SignupMutationError = void | HTTPValidationError
|
||||
|
||||
/**
|
||||
* @summary 회원가입
|
||||
*/
|
||||
export const useSignup = <TError = void | HTTPValidationError,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof signup>>, TError,{data: ReqSignup}, TContext>, request?: SecondParameter<typeof customFetch>}
|
||||
, queryClient?: QueryClient): UseMutationResult<
|
||||
Awaited<ReturnType<typeof signup>>,
|
||||
TError,
|
||||
{data: ReqSignup},
|
||||
TContext
|
||||
> => {
|
||||
|
||||
const mutationOptions = getSignupMutationOptions(options);
|
||||
|
||||
return useMutation(mutationOptions, queryClient);
|
||||
}
|
||||
/**
|
||||
* 구글 ID 토큰(GIS credential)을 검증하고 JWT 토큰을 발급한다. 처음 온 계정은 그 자리에서 만든다.
|
||||
* @summary 구글 로그인
|
||||
*/
|
||||
export const googleLogin = (
|
||||
reqGoogleLogin: ReqGoogleLogin,
|
||||
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
|
||||
) => {
|
||||
|
||||
|
||||
return customFetch<ResLogin>(
|
||||
{url: `/v1/auth/google`, method: 'POST',
|
||||
headers: {'Content-Type': 'application/json', },
|
||||
data: reqGoogleLogin, signal
|
||||
},
|
||||
options);
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const getGoogleLoginMutationOptions = <TError = void | HTTPValidationError,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof googleLogin>>, TError,{data: ReqGoogleLogin}, TContext>, request?: SecondParameter<typeof customFetch>}
|
||||
): UseMutationOptions<Awaited<ReturnType<typeof googleLogin>>, TError,{data: ReqGoogleLogin}, TContext> => {
|
||||
|
||||
const mutationKey = ['googleLogin'];
|
||||
const {mutation: mutationOptions, request: requestOptions} = options ?
|
||||
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
|
||||
options
|
||||
: {...options, mutation: {...options.mutation, mutationKey}}
|
||||
: {mutation: { mutationKey, }, request: undefined};
|
||||
|
||||
|
||||
|
||||
|
||||
const mutationFn: MutationFunction<Awaited<ReturnType<typeof googleLogin>>, {data: ReqGoogleLogin}> = (props) => {
|
||||
const {data} = props ?? {};
|
||||
|
||||
return googleLogin(data,requestOptions)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return { mutationFn, ...mutationOptions }}
|
||||
|
||||
export type GoogleLoginMutationResult = NonNullable<Awaited<ReturnType<typeof googleLogin>>>
|
||||
export type GoogleLoginMutationBody = ReqGoogleLogin
|
||||
export type GoogleLoginMutationError = void | HTTPValidationError
|
||||
|
||||
/**
|
||||
* @summary 구글 로그인
|
||||
*/
|
||||
export const useGoogleLogin = <TError = void | HTTPValidationError,
|
||||
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof googleLogin>>, TError,{data: ReqGoogleLogin}, TContext>, request?: SecondParameter<typeof customFetch>}
|
||||
, queryClient?: QueryClient): UseMutationResult<
|
||||
Awaited<ReturnType<typeof googleLogin>>,
|
||||
TError,
|
||||
{data: ReqGoogleLogin},
|
||||
TContext
|
||||
> => {
|
||||
|
||||
const mutationOptions = getGoogleLoginMutationOptions(options);
|
||||
|
||||
return useMutation(mutationOptions, queryClient);
|
||||
}
|
||||
/**
|
||||
* refresh 토큰으로 access 토큰을 재발급한다.
|
||||
* @summary 액세스 토큰 갱신
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* users.provider 코드값. 이 계정이 무엇으로 신원을 증명하는가.
|
||||
|
||||
한 계정은 수단 하나다 — 같은 이메일이라도 id/pw 계정과 구글 계정을 자동으로 잇지 않는다.
|
||||
이으려면 "먼저 가입한 쪽의 소유"를 증명받아야 하는데, 그 증명 없이 이메일만 보고 이으면
|
||||
남이 먼저 만들어 둔 계정에 내 구글 로그인이 들어간다(계정 선점). 보류 사유는 DECISIONS.md 1절.
|
||||
*/
|
||||
export type AuthProvider = typeof AuthProvider[keyof typeof AuthProvider];
|
||||
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
||||
export const AuthProvider = {
|
||||
LOCAL: 1,
|
||||
GOOGLE: 2,
|
||||
} as const;
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
export * from './auditCheckData';
|
||||
export * from './auditCheckDataRecommendation';
|
||||
export * from './authProvider';
|
||||
export * from './buildStatus';
|
||||
export * from './checkSlugParams';
|
||||
export * from './companyData';
|
||||
@@ -120,8 +121,12 @@ export * from './reqCreatePlace';
|
||||
export * from './reqCreatePlaceOwnerUserId';
|
||||
export * from './reqCreateUnit';
|
||||
export * from './reqExtractFacts';
|
||||
export * from './reqGoogleLogin';
|
||||
export * from './reqLogin';
|
||||
export * from './reqPublishLocalContent';
|
||||
export * from './reqSignup';
|
||||
export * from './reqSignupCompanyName';
|
||||
export * from './reqSignupName';
|
||||
export * from './reqSiteSlug';
|
||||
export * from './reqSiteStatus';
|
||||
export * from './reqSiteTemplate';
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* 구글 로그인. 프론트(GIS)가 받은 ID 토큰을 그대로 넘긴다.
|
||||
|
||||
필드 이름이 `credential` 인 이유는 GIS 콜백이 주는 이름 그대로이기 때문이다 —
|
||||
`access_token`/`id_token` 으로 바꿔 부르면 우리 토큰과 헷갈린다.
|
||||
*/
|
||||
export interface ReqGoogleLogin {
|
||||
credential?: string;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import type { ReqSignupName } from './reqSignupName';
|
||||
import type { ReqSignupCompanyName } from './reqSignupCompanyName';
|
||||
|
||||
/**
|
||||
* id/pw 가입. 가입 = 새 테넌트(회사) 1개 + 그 회사의 첫 계정 1개다.
|
||||
|
||||
★ 이메일을 필수로 받는 이유: 같은 이메일이 이미 구글로 가입돼 있는지 판단할 근거가 없으면
|
||||
한 사람에게 계정이 둘 생긴다. 지금 이메일 인증 절차는 없다 — 소유 증명이 아니라
|
||||
**중복 판정용** 이다.
|
||||
*/
|
||||
export interface ReqSignup {
|
||||
id?: string;
|
||||
password?: string;
|
||||
name?: ReqSignupName;
|
||||
email?: string;
|
||||
company_name?: ReqSignupCompanyName;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type ReqSignupCompanyName = string | null;
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type ReqSignupName = string | null;
|
||||
@@ -10,6 +10,7 @@ import type { ResMeName } from './resMeName';
|
||||
import type { ResMeEmail } from './resMeEmail';
|
||||
import type { ResMeContactNumber } from './resMeContactNumber';
|
||||
import type { UserRole } from './userRole';
|
||||
import type { AuthProvider } from './authProvider';
|
||||
import type { ResMeCompany } from './resMeCompany';
|
||||
|
||||
export interface ResMe {
|
||||
@@ -21,5 +22,6 @@ export interface ResMe {
|
||||
email?: ResMeEmail;
|
||||
contact_number?: ResMeContactNumber;
|
||||
role?: UserRole;
|
||||
provider?: AuthProvider;
|
||||
company?: ResMeCompany;
|
||||
}
|
||||
Reference in new issue
Block a user