Skip to content

Commit

Permalink
FPO-292
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee365 committed Jul 18, 2024
1 parent 0ec2877 commit 1eb6cca
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ if (isDev) {
app.use(httpRequestLoggingMiddleware())
app.use(scpConfiguration.middleware)
nunjucksConfiguration.addGlobal('baseURL', scpConfiguration.baseURL)
app.set('baseURL', scpConfiguration.baseURL)
}

configureSecurity(app)
Expand Down
15 changes: 13 additions & 2 deletions src/config/main-navigation-options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type NextFunction, type Response } from 'express'
import { logger } from './logging'

export default function (req: any, res: Response, next: NextFunction): void {
const mainNavigation: any = []
Expand All @@ -11,8 +12,18 @@ export default function (req: any, res: Response, next: NextFunction): void {
})

const userProfile = req.appSession?.userProfile ?? {}
const profileUrl = userProfile.profile ?? null
const groupUrl = userProfile['bas:groupProfile'] ?? null
let profileUrl = userProfile.profile ?? null
let groupUrl = userProfile['bas:groupProfile'] ?? null
const baseUrl: string = req.app.get('baseURL') ?? ''

if (profileUrl != null) {
profileUrl = profileUrl + '?redirect_uri=' + encodeURIComponent(baseUrl) + '/auth/profile-redirect'
}

if (groupUrl != null) {
groupUrl = groupUrl + '?redirect_uri=' + encodeURIComponent(baseUrl) + '/auth/group-redirect'
}
logger.debug(`scpConfigBaseURL: ${baseUrl} for userProfile: ${profileUrl} and groupUrl: ${groupUrl}`)

mainNavigation.push({
href: profileUrl,
Expand Down
5 changes: 5 additions & 0 deletions src/controllers/returnURLController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { type Request, type Response } from 'express'

export const returnURLPage = (req: Request, res: Response): void => {
res.redirect('dashboard')
}
3 changes: 3 additions & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { cookiesPage } from '../controllers/cookiesController'
import { rejectedPage } from '../controllers/rejectedController'
import { requiresAuth } from 'express-openid-connect'
import { body } from 'express-validator'
import { returnURLPage } from '../controllers/returnURLController'

const healthchecksController = new HealthchecksController()
const router: Router = express.Router()
Expand All @@ -17,6 +18,8 @@ router.get('/healthcheck', (req, res) => { healthchecksController.show(req, res)
router.get('/healthcheckz', (req, res) => { healthchecksController.showz(req, res) })
router.get('/privacyPolicy', privacyPolicyPage)
router.get('/cookies', cookiesPage)
router.get('/auth/profile-redirect', returnURLPage)
router.get('/auth/group-redirect', returnURLPage)

const isProduction = (process.env.NODE_ENV ?? 'development') === 'production'

Expand Down

0 comments on commit 1eb6cca

Please sign in to comment.