feat: add initial API

This commit is contained in:
Morten Olsen
2025-10-16 20:54:31 +02:00
parent 5cf0a3612a
commit 11828da073
17 changed files with 647 additions and 89 deletions

View File

@@ -1,4 +1,5 @@
import type { AuthProvider } from '#root/auth/auth.provider.ts';
import { Session } from './sessions.session.ts';
class SessionProvider {
#handlers: Map<string, AuthProvider>;
@@ -7,6 +8,10 @@ class SessionProvider {
this.#handlers = new Map();
}
public get providers() {
return Array.from(this.#handlers.keys());
}
public register = (name: string, provider: AuthProvider) => {
this.#handlers.set(name, provider);
};
@@ -18,6 +23,15 @@ class SessionProvider {
}
return handler.getAccess(token);
};
public get = async (provider: string, token: string) => {
const handler = this.#handlers.get(provider);
if (!handler) {
throw new Error('Provider not available');
}
const access = await handler.getAccess(token);
return new Session(access);
};
}
export { SessionProvider };