mirror of
https://github.com/nicotsx/zerobyte.git
synced 2026-04-18 05:47:31 -04:00
30 lines
653 B
TypeScript
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;
|
|
}
|