This commit is contained in:
seb
2026-11-03 03:54:49 +01:00
parent de2957acf1
commit 44e91a6973
4 changed files with 21 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ import jwt from 'jsonwebtoken';
import { OAuth2Client } from 'google-auth-library';
import env from '../../../config/env.js';
import * as db from '../../../db/googleAuth.js';
import * as autoinviteDb from '../../../db/autoinvite.js';
import { clearCachedUser } from '../../middleware/auth.js';
import { downloadPicture, toPictureBuffer } from '../../../util/pictureBinary.js';
@@ -20,7 +21,8 @@ export function register(app, basePath = '') {
* tags: [Auth]
* summary: Login with Google ID token
* description: |
* Verifies a Google ID token, checks allowlist (or creates entry when `IMPLICIT_CREATE=true`),
* Verifies a Google ID token, checks allowlist (or creates entry when `IMPLICIT_CREATE=true`
* or when the email has a pending auto-invitation),
* stores Google `sub` and profile image bytes, and sets an HTTP-only `token` cookie.
* `user.picture` is the profile image as base64 (same as GET /auth/me).
* security: []
@@ -64,7 +66,7 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
* 403:
* description: Email not on allowlist
* description: Email not on allowlist or invited
* content:
* application/json:
* schema:
@@ -104,7 +106,7 @@ export function register(app, basePath = '') {
}
let allowed = await db.getAllowedEmail(email);
if (!allowed && env.implicitCreate) {
if (!allowed && (env.implicitCreate || (await autoinviteDb.hasPendingInvite(email)))) {
await db.addAllowedEmail(email);
allowed = await db.getAllowedEmail(email);
}