mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-29 11:31:32 +00:00
UBERF-6310: Fix context passing (#5167)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
dc7512a844
commit
1664419b7b
@ -6,7 +6,7 @@ import { Strategy as GitHubStrategy } from 'passport-github2'
|
||||
import { Passport } from '.'
|
||||
|
||||
export function registerGithub (
|
||||
ctx: MeasureContext,
|
||||
measureCtx: MeasureContext,
|
||||
passport: Passport,
|
||||
router: Router<any, any>,
|
||||
accountsUrl: string,
|
||||
@ -45,23 +45,27 @@ export function registerGithub (
|
||||
const email = ctx.state.user.emails?.[0]?.value ?? `github:${ctx.state.user.username}`
|
||||
const [first, last] = ctx.state.user.displayName.split(' ')
|
||||
if (email !== undefined) {
|
||||
if (ctx.query?.state != null) {
|
||||
const loginInfo = await joinWithProvider(ctx, db, productId, email, first, last, ctx.query.state, {
|
||||
githubId: ctx.state.user.id
|
||||
})
|
||||
if (ctx.session != null) {
|
||||
ctx.session.loginInfo = loginInfo
|
||||
}
|
||||
} else {
|
||||
const loginInfo = await loginWithProvider(ctx, db, productId, email, first, last, {
|
||||
githubId: ctx.state.user.id
|
||||
})
|
||||
if (ctx.session != null) {
|
||||
ctx.session.loginInfo = loginInfo
|
||||
try {
|
||||
if (ctx.query?.state != null) {
|
||||
const loginInfo = await joinWithProvider(measureCtx, db, productId, email, first, last, ctx.query.state, {
|
||||
githubId: ctx.state.user.id
|
||||
})
|
||||
if (ctx.session != null) {
|
||||
ctx.session.loginInfo = loginInfo
|
||||
}
|
||||
} else {
|
||||
const loginInfo = await loginWithProvider(measureCtx, db, productId, email, first, last, {
|
||||
githubId: ctx.state.user.id
|
||||
})
|
||||
if (ctx.session != null) {
|
||||
ctx.session.loginInfo = loginInfo
|
||||
}
|
||||
}
|
||||
// Successful authentication, redirect to your application
|
||||
ctx.redirect(concatLink(frontUrl, '/login/auth'))
|
||||
} catch (err: any) {
|
||||
await measureCtx.error('failed to auth', err)
|
||||
}
|
||||
// Successful authentication, redirect to your application
|
||||
ctx.redirect(concatLink(frontUrl, '/login/auth'))
|
||||
}
|
||||
await next()
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import { Strategy as GoogleStrategy } from 'passport-google-oauth20'
|
||||
import { Passport } from '.'
|
||||
|
||||
export function registerGoogle (
|
||||
ctx: MeasureContext,
|
||||
measureCtx: MeasureContext,
|
||||
passport: Passport,
|
||||
router: Router<any, any>,
|
||||
accountsUrl: string,
|
||||
@ -46,19 +46,24 @@ export function registerGoogle (
|
||||
const first = ctx.state.user.name.givenName
|
||||
const last = ctx.state.user.name.familyName
|
||||
if (email !== undefined) {
|
||||
if (ctx.query?.state != null) {
|
||||
const loginInfo = await joinWithProvider(ctx, db, productId, email, first, last, ctx.query.state)
|
||||
if (ctx.session != null) {
|
||||
ctx.session.loginInfo = loginInfo
|
||||
}
|
||||
} else {
|
||||
const loginInfo = await loginWithProvider(ctx, db, productId, email, first, last)
|
||||
if (ctx.session != null) {
|
||||
ctx.session.loginInfo = loginInfo
|
||||
try {
|
||||
if (ctx.query?.state != null) {
|
||||
const loginInfo = await joinWithProvider(measureCtx, db, productId, email, first, last, ctx.query.state)
|
||||
if (ctx.session != null) {
|
||||
ctx.session.loginInfo = loginInfo
|
||||
}
|
||||
} else {
|
||||
const loginInfo = await loginWithProvider(measureCtx, db, productId, email, first, last)
|
||||
if (ctx.session != null) {
|
||||
ctx.session.loginInfo = loginInfo
|
||||
}
|
||||
}
|
||||
|
||||
// Successful authentication, redirect to your application
|
||||
ctx.redirect(concatLink(frontUrl, '/login/auth'))
|
||||
} catch (err: any) {
|
||||
await measureCtx.error('failed to auth', err)
|
||||
}
|
||||
// Successful authentication, redirect to your application
|
||||
ctx.redirect(concatLink(frontUrl, '/login/auth'))
|
||||
}
|
||||
await next()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user