mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-06-17 00:40:15 +00:00
a0e74cd5f2
Co-authored-by: Claude <noreply@anthropic.com>
41 lines
974 B
TypeScript
41 lines
974 B
TypeScript
import { z } from "zod";
|
|
|
|
type ScreenParams = {
|
|
login_for?: "oidc" | "app";
|
|
redirect_uri?: string;
|
|
oidc_ticket?: string;
|
|
oidc_scope?: string;
|
|
oidc_name?: string;
|
|
};
|
|
|
|
const zodScreenParams = z.object({
|
|
login_for: z.enum(["oidc", "app"]).optional(),
|
|
redirect_uri: z.string().optional(),
|
|
oidc_ticket: z.string().optional(),
|
|
oidc_scope: z.string().optional(),
|
|
oidc_name: z.string().optional(),
|
|
});
|
|
|
|
export function useScreenParams(params: URLSearchParams): ScreenParams {
|
|
const paramsObj = Object.fromEntries(params.entries());
|
|
const parsed = zodScreenParams.safeParse(paramsObj);
|
|
if (!parsed.success) {
|
|
return {};
|
|
}
|
|
return parsed.data;
|
|
}
|
|
|
|
export function recompileScreenParams(params: ScreenParams): string {
|
|
const p = new URLSearchParams(
|
|
Object.fromEntries(
|
|
Object.entries(params).filter(([, v]) => v !== undefined),
|
|
) as Record<string, string>,
|
|
).toString();
|
|
|
|
if (p.length > 0) {
|
|
return "?" + p;
|
|
}
|
|
|
|
return "";
|
|
}
|