Skip to content

Commit

Permalink
본인인증 여러번 할 수 있게 수정 (#2860)
Browse files Browse the repository at this point in the history
본인인증 1년 지난 사람들이 재인증을 못함
  • Loading branch information
robin-maki committed Dec 12, 2024
1 parent b06a1e0 commit 6d2fc53
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
25 changes: 9 additions & 16 deletions apps/website/src/lib/server/graphql/schemas/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { webcrypto } from 'node:crypto';
import dayjs from 'dayjs';
import { and, asc, count, desc, eq, gt, gte, lt, or } from 'drizzle-orm';
import { and, asc, count, desc, eq, gt, gte, lt, ne, or } from 'drizzle-orm';
import { nanoid } from 'nanoid';
import qs from 'query-string';
import * as R from 'radash';
Expand Down Expand Up @@ -1482,14 +1482,16 @@ builder.mutationFields((t) => ({
.select({ id: UserPersonalIdentities.id, userId: UserPersonalIdentities.userId })
.from(UserPersonalIdentities)
.innerJoin(Users, eq(Users.id, UserPersonalIdentities.userId))
.where(and(eq(UserPersonalIdentities.ci, resp.response.unique_key), eq(Users.state, 'ACTIVE')));
.where(
and(
eq(UserPersonalIdentities.ci, resp.response.unique_key),
eq(Users.state, 'ACTIVE'),
ne(UserPersonalIdentities.userId, context.session.userId),
),
);

if (identities.length > 0) {
if (identities[0].userId === context.session.userId) {
return identities[0].id;
} else {
throw new IntentionalError('이미 인증된 다른 계정이 있어요');
}
throw new IntentionalError('이미 인증된 다른 계정이 있어요');
}

const [identity] = await database
Expand Down Expand Up @@ -1608,15 +1610,6 @@ builder.mutationFields((t) => ({
type: User,
args: { input: t.arg({ type: VerifyPassportIdentityInput }) },
resolve: async (_, { input }, context) => {
const personalIdentities = await database
.select({ id: UserPersonalIdentities.id })
.from(UserPersonalIdentities)
.where(eq(UserPersonalIdentities.userId, context.session.userId));

if (personalIdentities.length > 0) {
throw new IntentionalError('이미 본인인증된 계정이에요');
}

const passportVerification = await coocon.verifyPassportNumber({
name: input.name,
birthday: input.birthday,
Expand Down
6 changes: 2 additions & 4 deletions apps/website/src/lib/server/rest/routes/identification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ identification.get('/identification/callback', async (_, context) => {
headers: { Location: '/find-account/complete' },
});
} else if (context.session) {
if (identity) {
await (identity.userId === context.session.userId
? context.flash('error', '이미 본인인증이 완료되었어요')
: context.flash('error', '이미 인증된 다른 계정이 있어요'));
if (identity && identity.userId !== context.session.userId) {
context.flash('error', '이미 인증된 다른 계정이 있어요');
return status(303, { headers: { Location: '/me/settings' } });
}

Expand Down
7 changes: 4 additions & 3 deletions apps/website/src/lib/server/utils/age.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dayjs from 'dayjs';
import { and, gt, inArray } from 'drizzle-orm';
import { and, desc, gt, inArray } from 'drizzle-orm';
import * as R from 'radash';
import * as E from '$lib/enums';
import { database, UserPersonalIdentities } from '../database';
Expand Down Expand Up @@ -65,9 +65,10 @@ export const getPersonalIdentity = async (userId: string | undefined, context: P
nullable: true,
load: async (userIds: string[]) => {
return database
.select()
.selectDistinctOn([UserPersonalIdentities.userId])
.from(UserPersonalIdentities)
.where(and(inArray(UserPersonalIdentities.userId, userIds), gt(UserPersonalIdentities.expiresAt, dayjs())));
.where(and(inArray(UserPersonalIdentities.userId, userIds), gt(UserPersonalIdentities.expiresAt, dayjs())))
.orderBy(UserPersonalIdentities.userId, desc(UserPersonalIdentities.createdAt));
},

key: (identity) => identity?.userId,
Expand Down

0 comments on commit 6d2fc53

Please sign in to comment.