tethys.backend/config/auth.ts

90 lines
3.2 KiB
TypeScript
Raw Permalink Normal View History

2024-03-14 19:25:27 +00:00
import { defineConfig } from '@adonisjs/auth';
import { Authenticators } from '@adonisjs/auth/types';
import { sessionGuard, sessionUserProvider } from '@adonisjs/auth/session';
// import User from '#models/user';
2024-03-14 19:25:27 +00:00
// import { SessionLucidUserProviderOptions } from '@adonisjs/auth/types/session';
import { Authenticator } from '@adonisjs/auth';
import { GuardFactory } from '@adonisjs/auth/types';
2023-03-03 15:54:28 +00:00
2024-03-14 19:25:27 +00:00
// export declare function sessionUserProvider<Model extends LucidAuthenticatable>(config: SessionLucidUserProviderOptions<Model>): SessionLucidUserProvider<Model>;
2023-03-03 15:54:28 +00:00
2024-03-14 19:25:27 +00:00
const authConfig = defineConfig({
default: 'web',
2023-03-03 15:54:28 +00:00
guards: {
2024-03-14 19:25:27 +00:00
web: sessionGuard({
useRememberMeTokens: false,
provider: sessionUserProvider({
model: () => import('#models/user'),
2024-03-14 19:25:27 +00:00
}),
}),
},
});
export default authConfig;
2023-03-03 15:54:28 +00:00
2024-03-14 19:25:27 +00:00
/**
* Inferring types from the configured auth
* guards.
*/
declare module '@adonisjs/auth/types' {
// export type InferAuthenticators<
// Config extends ConfigProvider<{
// default: unknown;
// guards: unknown;
// }>,
// > = Awaited<ReturnType<Config['resolver']>>['guards'];
// interface ProvidersList {
// /*
// |--------------------------------------------------------------------------
// | User Provider
// |--------------------------------------------------------------------------
// |
// | The following provider uses Lucid models as a driver for fetching user
// | details from the database for authentication.
// |
// | You can create multiple providers using the same underlying driver with
// | different Lucid models.
// |
// */
// // user: {
// // implementation: SessionLucidUserProvider<typeof User>;
// // config: LucidProviderConfig<typeof User>;
// // };
// user: {
// implementation: SessionLucidUserProvider<typeof User>;
// config: SessionLucidUserProviderOptions<typeof User>;
// };
// }
2023-03-03 15:54:28 +00:00
2024-03-14 19:25:27 +00:00
interface Authenticators extends InferAuthenticators<typeof authConfig> {}
2023-03-03 15:54:28 +00:00
2024-03-14 19:25:27 +00:00
// const PROVIDER_REAL_USER: unique symbol;
// export type SessionGuardUser<RealUser> = {
// getId(): string | number | BigInt;
// getOriginal(): RealUser;
// };
2023-03-03 15:54:28 +00:00
2024-03-14 19:25:27 +00:00
// export interface SessionUserProviderContract<User> {
// [PROVIDER_REAL_USER]: User;
// /**
// * Create a user object that acts as an adapter between
// * the guard and real user value.
// */
// createUserForGuard(user: User): Promise<SessionGuardUser<User>>;
// /**
// * Find a user by their id.
// */
// findById(identifier: string | number | BigInt): Promise<SessionGuardUser<User> | null>;
// }
}
2023-03-03 15:54:28 +00:00
2024-03-14 19:25:27 +00:00
// declare module '@adonisjs/core/types' {
// interface EventsList extends InferAuthEvents<Authenticators> {}
// }
declare module '@adonisjs/core/http' {
interface HttpContext {
auth: Authenticator<Authenticators extends Record<string, GuardFactory> ? Authenticators : never>;
}
}