Skip to content

Commit 2490b67

Browse files
committed
fix: redirect url bug when google login callback
1 parent 0a938cd commit 2490b67

File tree

15 files changed

+28
-18
lines changed

15 files changed

+28
-18
lines changed

apps/server/src/app.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Fastify from 'fastify'
22
import formbody from '@fastify/formbody'
33
import cookie from '@fastify/cookie'
44
import { ENV } from '@env'
5-
import routes from '@routes/index.js'
5+
import routes from '@routes/index.mjs'
66
import multer from 'fastify-multer'
77
import validatorCompilerPlugin from '@plugins/global/validatorCompilerPlugin.mjs'
88
import authPlugin from '@plugins/global/authPlugin.mjs'

apps/server/src/lib/utils/UtilsService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { fileURLToPath } from 'url'
55
import { z } from 'zod'
66
import { customAlphabet } from 'nanoid'
77
import nanoidDictionary from 'nanoid-dictionary'
8+
import { UtilsService as Utils } from '@packages/library/utils'
89

910
interface Service {
1011
resolveDir(dir: string): string
@@ -28,7 +29,7 @@ interface Service {
2829

2930
@injectable()
3031
@singleton()
31-
export class UtilsService implements Service {
32+
export class UtilsService extends Utils implements Service {
3233
public resolveDir(dir: string): string {
3334
const __filename = fileURLToPath(import.meta.url)
3435
const splited = dirname(__filename).split('/src')

apps/server/src/routes/auth/index.ts renamed to apps/server/src/routes/auth/index.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import v3 from './v3/index.js'
1+
import v3 from './v3/index.mjs'
22

33
import { FastifyPluginCallback } from 'fastify'
44

apps/server/src/routes/auth/v3/index.ts renamed to apps/server/src/routes/auth/v3/index.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import socialRoute from '@routes/auth/v3/social/index.js'
1+
import socialRoute from '@routes/auth/v3/social/index.mjs'
22
import { FastifyPluginCallback } from 'fastify'
33

44
const v3: FastifyPluginCallback = (fastify, opts, done) => {

apps/server/src/routes/auth/v3/social/SocialController.ts renamed to apps/server/src/routes/auth/v3/social/SocialController.mts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { UnauthorizedError } from '@errors/UnauthorizedError.js'
2020
import { ConfilctError } from '@errors/ConfilctError.js'
2121
import { BadRequestError } from '@errors/BadRequestErrors.js'
2222
import { NotFoundError } from '@errors/NotfoundError.js'
23+
import { UtilsService } from '@lib/utils/UtilsService.js'
2324

2425
interface Controller {
2526
googleCallback(request: FastifyRequest<{ Querystring: { code: string } }>): Promise<void>
@@ -46,6 +47,7 @@ export class SocialController implements Controller {
4647
private readonly cookie: CookieService,
4748
private readonly file: FileService,
4849
private readonly b2Manager: B2ManagerService,
50+
private readonly utils: UtilsService,
4951
private readonly externalInterationService: ExternalIntegrationService,
5052
) {}
5153
private get redirectUri(): string {
@@ -138,7 +140,7 @@ export class SocialController implements Controller {
138140
maxAge: Time.ONE_DAY_IN_S * 30,
139141
})
140142

141-
const redirectUrl = ENV.clientV3Host
143+
const redirectHost = ENV.clientV3Host
142144
const state = queryState
143145
? (JSON.parse(queryState) as { next: string; integrateState?: string })
144146
: null
@@ -154,7 +156,10 @@ export class SocialController implements Controller {
154156
}
155157
}
156158

157-
reply.redirect(decodeURI(redirectUrl.concat(next)))
159+
const redirectUri = this.utils
160+
.removeKoreanChars(decodeURI(redirectHost.concat(next)))
161+
.trim()
162+
reply.redirect(redirectUri)
158163
return
159164
}
160165
}

apps/server/src/routes/auth/v3/social/index.ts renamed to apps/server/src/routes/auth/v3/social/index.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SocialController } from '@routes/auth/v3/social/SocialController.js'
1+
import { SocialController } from '@routes/auth/v3/social/SocialController.mjs'
22
import { SocialProvider } from '@services/SocialService/SocialServiceInterface.js'
33
import { FastifyPluginCallback, FastifyReply, FastifyRequest } from 'fastify'
44
import { container } from 'tsyringe'

apps/server/src/routes/files/index.ts renamed to apps/server/src/routes/files/index.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FastifyPluginCallback } from 'fastify'
2-
import v3 from './v3/index.js'
2+
import v3 from './v3/index.mjs'
33

44
const filesRoute: FastifyPluginCallback = (fastify, opts, done) => {
55
fastify.register(v3, { prefix: '/v3' })

apps/server/src/routes/files/v3/filesController.ts renamed to apps/server/src/routes/files/v3/filesController.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { injectable, singleton } from 'tsyringe'
22
import { AwsService } from '@lib/aws/AwsService.js'
3-
import { CreateUrlBody, UploadBody } from './schema.js'
3+
import { CreateUrlBody, UploadBody } from './schema.mjs'
44
import { UnauthorizedError } from '@errors/UnauthorizedError.js'
55
import { UserService } from '@services/UserService/index.js'
66
import { DbService } from '@lib/db/DbService.js'

apps/server/src/routes/files/v3/index.ts renamed to apps/server/src/routes/files/v3/index.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { FastifyPluginCallback } from 'fastify'
22
import { container } from 'tsyringe'
33
import multer from 'fastify-multer'
4-
import { CreateUrlBody, UploadBody, createUrlBodySchema } from './schema.js'
5-
import { FilesController } from './filesController.js'
4+
import { CreateUrlBody, UploadBody, createUrlBodySchema } from './schema.mjs'
5+
import { FilesController } from './filesController.mjs'
66
import authGuardPlugin from '@plugins/encapsulated/authGuardPlugin.js'
77

88
const v3: FastifyPluginCallback = (fastify, opts, done) => {

apps/server/src/routes/index.ts renamed to apps/server/src/routes/index.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import authRoute from '@routes/auth/index.js'
2-
import postsRoute from '@routes/posts/index.js'
3-
import filesRoute from '@routes/files/index.js'
1+
import authRoute from '@routes/auth/index.mjs'
2+
import postsRoute from '@routes/posts/index.mjs'
3+
import filesRoute from '@routes/files/index.mjs'
44
import { format } from 'date-fns'
55
import type { FastifyPluginCallback } from 'fastify'
66

apps/server/src/routes/posts/index.ts renamed to apps/server/src/routes/posts/index.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import v3 from './v3/index.js'
1+
import v3 from './v3/index.mjs'
22

33
import { FastifyPluginCallback } from 'fastify'
44

apps/server/src/routes/posts/v3/index.ts renamed to apps/server/src/routes/posts/v3/index.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HttpStatus } from '@constants/HttpStatusConstants.js'
22
import { HttpStatusMessage } from '@constants/HttpStatusMesageConstants.js'
3-
import { postScoreParamsSchema } from '@routes/posts/v3/schame.js'
3+
import { postScoreParamsSchema } from '@routes/posts/v3/schame.mjs'
44
import { PostService } from '@services/PostService/index.js'
55
import { FastifyPluginCallback } from 'fastify'
66
import { FromSchema } from 'json-schema-to-ts'

packages/library/src/utils/UtilsService.mts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import nanoidDictionary from 'nanoid-dictionary'
44
interface Service {
55
escapeForUrl(text: string): string
66
randomString(): string
7-
sleep(ms: number): Promise<any>
7+
sleep(ms: number): Promise<void>
8+
removeKoreanChars(str: string): string
89
}
910

1011
export class UtilsService implements Service {
@@ -23,7 +24,10 @@ export class UtilsService implements Service {
2324
const generateCode = customAlphabet(nanoidDictionary.alphanumeric, size)
2425
return generateCode()
2526
}
26-
public sleep(ms: number) {
27+
public sleep(ms: number): Promise<void> {
2728
return new Promise((resolve) => setTimeout(resolve, ms))
2829
}
30+
public removeKoreanChars(str: string): string {
31+
return str.replace(/[\uAC00-\uD7A3\u3131-\u3163]/g, '')
32+
}
2933
}

0 commit comments

Comments
 (0)