Files
wiki/tina/auth/oidc-provider.ts
vorpax 6be40f5a6a tina
2026-02-02 04:14:53 +01:00

28 lines
691 B
TypeScript

import { AbstractAuthProvider } from "tinacms";
export class OIDCAuthProvider extends AbstractAuthProvider {
async authenticate(): Promise<any> {
window.location.href = "/auth/login";
}
async getUser(): Promise<any> {
// Appel à une route /api/me pour récupérer l'utilisateur
const res = await fetch("/api/me", {
credentials: "include",
});
if (res.ok) {
return await res.json();
}
return null;
}
async getToken(): Promise<{ id_token: string }> {
// Le token est géré par les cookies, pas besoin de le retourner
return { id_token: "" };
}
async logout(): Promise<void> {
window.location.href = "/auth/logout";
}
}