mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-07 16:30:49 +00:00
Extra logs for auth providers (#5840)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
d1f6a9de7f
commit
279b04f5b2
@ -35,6 +35,7 @@ export function registerGithub (
|
||||
|
||||
router.get('/auth/github', async (ctx, next) => {
|
||||
const state = ctx.query?.inviteId
|
||||
measureCtx.info('try auth via', { provider: 'github' })
|
||||
passport.authenticate('github', { scope: ['user:email'], session: true, state })(ctx, next)
|
||||
})
|
||||
|
||||
@ -45,6 +46,7 @@ export function registerGithub (
|
||||
try {
|
||||
const email = ctx.state.user.emails?.[0]?.value ?? `github:${ctx.state.user.username}`
|
||||
const [first, last] = ctx.state.user.displayName?.split(' ') ?? [ctx.state.user.username, '']
|
||||
measureCtx.info('Provider auth handler', { email, type: 'github' })
|
||||
if (email !== undefined) {
|
||||
if (ctx.query?.state != null) {
|
||||
const loginInfo = await joinWithProvider(
|
||||
@ -71,11 +73,12 @@ export function registerGithub (
|
||||
ctx.session.loginInfo = loginInfo
|
||||
}
|
||||
}
|
||||
measureCtx.info('Success auth, redirect', { email, type: 'github' })
|
||||
// Successful authentication, redirect to your application
|
||||
ctx.redirect(concatLink(frontUrl, '/login/auth'))
|
||||
}
|
||||
} catch (err: any) {
|
||||
measureCtx.error('failed to auth', err)
|
||||
measureCtx.error('failed to auth', { err, type: 'github', user: ctx.state?.user })
|
||||
}
|
||||
await next()
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ export function registerGoogle (
|
||||
|
||||
router.get('/auth/google', async (ctx, next) => {
|
||||
const state = ctx.query?.inviteId
|
||||
measureCtx.info('try auth via', { provider: 'google' })
|
||||
passport.authenticate('google', { scope: ['profile', 'email'], session: true, state })(ctx, next)
|
||||
})
|
||||
|
||||
@ -45,6 +46,7 @@ export function registerGoogle (
|
||||
const email = ctx.state.user.emails?.[0]?.value
|
||||
const first = ctx.state.user.name.givenName
|
||||
const last = ctx.state.user.name.familyName
|
||||
measureCtx.info('Provider auth handler', { email, type: 'google' })
|
||||
if (email !== undefined) {
|
||||
try {
|
||||
if (ctx.query?.state != null) {
|
||||
@ -69,9 +71,10 @@ export function registerGoogle (
|
||||
}
|
||||
|
||||
// Successful authentication, redirect to your application
|
||||
measureCtx.info('Success auth, redirect', { email, type: 'google' })
|
||||
ctx.redirect(concatLink(frontUrl, '/login/auth'))
|
||||
} catch (err: any) {
|
||||
measureCtx.error('failed to auth', err)
|
||||
measureCtx.error('failed to auth', { err, type: 'google', user: ctx.state?.user })
|
||||
}
|
||||
}
|
||||
await next()
|
||||
|
@ -2064,6 +2064,7 @@ export async function joinWithProvider (
|
||||
inviteId: ObjectId,
|
||||
extra?: Record<string, string>
|
||||
): Promise<WorkspaceLoginInfo | LoginInfo> {
|
||||
try {
|
||||
const email = cleanEmail(_email)
|
||||
const invite = await getInvite(db, inviteId)
|
||||
const workspace = await checkInvite(ctx, invite, email)
|
||||
@ -2115,7 +2116,6 @@ export async function joinWithProvider (
|
||||
await useInvite(db, inviteId)
|
||||
return result
|
||||
}
|
||||
|
||||
const newAccount = await createAcc(ctx, db, productId, branding, email, null, first, last, true, extra)
|
||||
const token = generateToken(email, getWorkspaceId('', productId), getExtra(newAccount))
|
||||
const ws = await assignWorkspace(
|
||||
@ -2133,6 +2133,11 @@ export async function joinWithProvider (
|
||||
await useInvite(db, inviteId)
|
||||
|
||||
return result
|
||||
} catch (err: any) {
|
||||
Analytics.handleError(err)
|
||||
ctx.error('joinWithProvider error', { email: _email, ...extra, err })
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
export async function loginWithProvider (
|
||||
@ -2145,6 +2150,7 @@ export async function loginWithProvider (
|
||||
last: string,
|
||||
extra?: Record<string, string>
|
||||
): Promise<LoginInfo> {
|
||||
try {
|
||||
const email = cleanEmail(_email)
|
||||
if (last == null) {
|
||||
last = ''
|
||||
@ -2173,6 +2179,11 @@ export async function loginWithProvider (
|
||||
token: generateToken(email, getWorkspaceId('', productId), getExtra(newAccount))
|
||||
}
|
||||
return result
|
||||
} catch (err: any) {
|
||||
Analytics.handleError(err)
|
||||
ctx.error('loginWithProvider error', { email: _email, ...extra, err })
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user