Files
zerobyte/app/server/lib/auth/utils/sso-context.ts
2026-02-24 11:55:05 +01:00

30 lines
653 B
TypeScript

import type { GenericEndpointContext } from "@better-auth/core";
export function normalizeEmail(email: string): string {
return email.trim().toLowerCase();
}
export function extractProviderIdFromContext(ctx?: GenericEndpointContext | null) {
if (!ctx) {
return null;
}
if (ctx.params?.providerId) {
return ctx.params.providerId;
}
if (ctx.request?.url) {
try {
const pathname = new URL(ctx.request.url, "http://localhost").pathname;
const ssoCallbackMatch = pathname.match(/\/sso\/(?:saml2\/)?callback\/([^/]+)$/);
if (ssoCallbackMatch) {
return ssoCallbackMatch[1];
}
} catch {
return null;
}
}
return null;
}