Checkpoint: Correction complémentaire : normalisation stricte des valeurs OAuth de loginMethod avant insertion DB, afin d’éviter les erreurs de troncature causées par les identifiants de plateforme externes. Ajout de tests associés et validation build complète.
This commit is contained in:
23
server/authMethod.ts
Normal file
23
server/authMethod.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/** Values accepted by the `users.loginMethod` database enum. */
|
||||
export type LoginMethod = "manus" | "local" | "azure-ad";
|
||||
|
||||
const LOGIN_METHODS = new Set<LoginMethod>(["manus", "local", "azure-ad"]);
|
||||
|
||||
/**
|
||||
* Maps provider-specific identifiers to the limited database enum.
|
||||
* OAuth identity payloads are external input and must never be persisted verbatim.
|
||||
*/
|
||||
export function normalizeLoginMethod(value: unknown): LoginMethod {
|
||||
if (typeof value !== "string") return "manus";
|
||||
|
||||
const normalized = value.trim().toLowerCase();
|
||||
if (LOGIN_METHODS.has(normalized as LoginMethod)) {
|
||||
return normalized as LoginMethod;
|
||||
}
|
||||
|
||||
if (normalized.includes("azure") || normalized.includes("microsoft")) {
|
||||
return "azure-ad";
|
||||
}
|
||||
|
||||
return "manus";
|
||||
}
|
||||
Reference in New Issue
Block a user