Customize route for first signin for tracking
This commit is contained in:
@ -77,7 +77,7 @@ router.get('google.callback', auth({ required: false }), async ctx => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const [user] = await User.findOrCreate({
|
const [user, isFirstSignin] = await User.findOrCreate({
|
||||||
where: {
|
where: {
|
||||||
service: 'google',
|
service: 'google',
|
||||||
serviceId: profile.data.id,
|
serviceId: profile.data.id,
|
||||||
@ -97,7 +97,7 @@ router.get('google.callback', auth({ required: false }), async ctx => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set cookies on response and redirect to team subdomain
|
// set cookies on response and redirect to team subdomain
|
||||||
ctx.signIn(user, team, 'google');
|
ctx.signIn(user, team, 'google', isFirstSignin);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -46,7 +46,7 @@ router.get('slack.callback', auth({ required: false }), async ctx => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const [user] = await User.findOrCreate({
|
const [user, isFirstSignin] = await User.findOrCreate({
|
||||||
where: {
|
where: {
|
||||||
service: 'slack',
|
service: 'slack',
|
||||||
serviceId: data.user.id,
|
serviceId: data.user.id,
|
||||||
@ -66,7 +66,7 @@ router.get('slack.callback', auth({ required: false }), async ctx => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set cookies on response and redirect to team subdomain
|
// set cookies on response and redirect to team subdomain
|
||||||
ctx.signIn(user, team, 'slack');
|
ctx.signIn(user, team, 'slack', isFirstSignin);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('slack.commands', auth(), async ctx => {
|
router.get('slack.commands', auth(), async ctx => {
|
||||||
|
@ -93,7 +93,7 @@ export default function auth(options?: { required?: boolean } = {}) {
|
|||||||
ctx.cache[user.id] = user;
|
ctx.cache[user.id] = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.signIn = (user, team, service) => {
|
ctx.signIn = (user, team, service, isFirstSignin = false) => {
|
||||||
// update the database when the user last signed in
|
// update the database when the user last signed in
|
||||||
user.updateSignedIn(ctx.request.ip);
|
user.updateSignedIn(ctx.request.ip);
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ export default function auth(options?: { required?: boolean } = {}) {
|
|||||||
httpOnly: false,
|
httpOnly: false,
|
||||||
expires,
|
expires,
|
||||||
});
|
});
|
||||||
ctx.redirect(`${team.url}/dashboard`);
|
ctx.redirect(`${team.url}/dashboard${isFirstSignin ? '?welcome' : ''}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user