mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
added: google oauth for manual registration was made
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
@@ -489,6 +489,17 @@ exports.googleCallback = async (req, res) => {
|
|||||||
await user.update({ email: `deleted_${user.user_id}@deleted.invalid` });
|
await user.update({ email: `deleted_${user.user_id}@deleted.invalid` });
|
||||||
user = null;
|
user = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A system (manual) registration signing in with Google for the first time
|
||||||
|
// gets folded into that same account rather than blocked or duplicated.
|
||||||
|
// From this point on the account is Google-only — mirrors the existing
|
||||||
|
// rule that blocks Google accounts from manual login/password reset.
|
||||||
|
let justLinkedGoogle = false;
|
||||||
|
if (user && user.reg_type === 'system') {
|
||||||
|
justLinkedGoogle = true;
|
||||||
|
await user.update({ reg_type: 'google' });
|
||||||
|
}
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
const t = await sequelize.transaction();
|
const t = await sequelize.transaction();
|
||||||
try {
|
try {
|
||||||
@@ -558,8 +569,13 @@ exports.googleCallback = async (req, res) => {
|
|||||||
|
|
||||||
logActivity(user.user_id, 'login', { entityType: 'session', entityId: Number(session.session_id) });
|
logActivity(user.user_id, 'login', { entityType: 'session', entityId: Number(session.session_id) });
|
||||||
|
|
||||||
// No cookie needed here — the refresh cookie set above is itself the
|
// Normally no cookie is needed here — the refresh cookie set above is
|
||||||
// signal. The frontend just calls restoreSession() and it succeeds.
|
// itself the signal, and the frontend just calls restoreSession(). The
|
||||||
|
// one exception is the just-linked flag, which restoreSession() has no
|
||||||
|
// way to surface on its own.
|
||||||
|
if (justLinkedGoogle) {
|
||||||
|
setGoogleResultCookie(res, { justLinkedGoogle: true });
|
||||||
|
}
|
||||||
return res.redirect(CALLBACK_PAGE);
|
return res.redirect(CALLBACK_PAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -569,7 +585,7 @@ exports.googleCallback = async (req, res) => {
|
|||||||
sendEmail({ to: user.email, type: 'LOGIN_OTP', data: { otp } })
|
sendEmail({ to: user.email, type: 'LOGIN_OTP', data: { otp } })
|
||||||
.catch(err => console.error('[AUTH] googleCallback: Failed to send login OTP email:', err));
|
.catch(err => console.error('[AUTH] googleCallback: Failed to send login OTP email:', err));
|
||||||
|
|
||||||
setGoogleResultCookie(res, { otpRequired: true, email: user.email });
|
setGoogleResultCookie(res, { otpRequired: true, email: user.email, justLinkedGoogle });
|
||||||
return res.redirect(CALLBACK_PAGE);
|
return res.redirect(CALLBACK_PAGE);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[AUTH] googleCallback OIDC error:', err);
|
console.error('[AUTH] googleCallback OIDC error:', err);
|
||||||
|
|||||||
Reference in New Issue
Block a user