Skip to content

Commit

Permalink
UBERF-6310: Fix context passing
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
  • Loading branch information
haiodo committed Apr 3, 2024
1 parent 1e4978c commit 10e1142
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
36 changes: 20 additions & 16 deletions pods/authProviders/src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}
Expand Down
29 changes: 17 additions & 12 deletions pods/authProviders/src/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}
Expand Down

0 comments on commit 10e1142

Please sign in to comment.