Skip to content

Commit

Permalink
fix: redirect to frontend app after myinfo log in (for local dev envi…
Browse files Browse the repository at this point in the history
…ronment) (#6743)

* feat: add feAppUrl as a new env var

* feat: change redirectDestination for local dev
  • Loading branch information
wanlingt authored Sep 22, 2023
1 parent 3531eac commit 04f1070
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ services:
- DB_HOST=mongodb://database:27017/formsg
- APP_NAME=FormSG
- APP_URL=http://localhost:5001
- FE_APP_URL=http://localhost:3000
- ATTACHMENT_S3_BUCKET=local-attachment-bucket
- IMAGE_S3_BUCKET=local-image-bucket
- LOGO_S3_BUCKET=local-logo-bucket
Expand Down
6 changes: 6 additions & 0 deletions src/app/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ export const optionalVarsSchema: Schema<IOptionalVarsSchema> = {
default: 'https://form.gov.sg',
env: 'APP_URL',
},
feAppUrl: {
doc: 'For local dev use only - frontend app url',
format: 'url',
default: 'https://form.gov.sg',
env: 'FE_APP_URL',
},
keywords: {
doc: 'Application keywords in meta tag',
format: String,
Expand Down
12 changes: 10 additions & 2 deletions src/app/modules/myinfo/myinfo.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { celebrate, Joi, Segments } from 'celebrate'
import { StatusCodes } from 'http-status-codes'

import { Environment } from '../../../types'
import config from '../../config/config'
import { createLoggerWithLabel } from '../../config/logger'
import { createReqMeta } from '../../utils/request'
import { ControllerHandler } from '../core/core.types'
Expand Down Expand Up @@ -139,11 +141,17 @@ export const loginToMyInfo: ControllerHandler<
}
const { formId, encodedQuery } = parseStateResult.value

let redirectDestination = `/${formId}`
// For local dev, we need to specify the frontend app URL as this is different from the backend's app URL
const redirectDestinationRaw =
process.env.NODE_ENV === Environment.Dev
? `${config.app.feAppUrl}/${formId}`
: `/${formId}`

let redirectDestination = redirectDestinationRaw

if (encodedQuery) {
try {
redirectDestination = `/${formId}?${Buffer.from(
redirectDestination = `${redirectDestinationRaw}?${Buffer.from(
encodedQuery,
'base64',
).toString('utf8')}`
Expand Down
1 change: 1 addition & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type AppConfig = {
title: string
description: string
appUrl: string
feAppUrl: string
keywords: string
images: string[]
twitterImage: string
Expand Down

0 comments on commit 04f1070

Please sign in to comment.