This commit is contained in:
parent
f828ca4491
commit
cb51a4136f
167 changed files with 21485 additions and 21212 deletions
163
config/auth.ts
163
config/auth.ts
|
@ -1,86 +1,89 @@
|
|||
/**
|
||||
* Config source: https://git.io/JY0mp
|
||||
*
|
||||
* Feel free to let us know via PR, if you find something broken in this config
|
||||
* file.
|
||||
*/
|
||||
import { defineConfig } from '@adonisjs/auth';
|
||||
import { Authenticators } from '@adonisjs/auth/types';
|
||||
import { sessionGuard, sessionUserProvider } from '@adonisjs/auth/session';
|
||||
// import User from '#app/Models/User';
|
||||
// import { SessionLucidUserProviderOptions } from '@adonisjs/auth/types/session';
|
||||
import { Authenticator } from '@adonisjs/auth';
|
||||
import { GuardFactory } from '@adonisjs/auth/types';
|
||||
|
||||
import type { AuthConfig } from '@ioc:Adonis/Addons/Auth';
|
||||
// export declare function sessionUserProvider<Model extends LucidAuthenticatable>(config: SessionLucidUserProviderOptions<Model>): SessionLucidUserProvider<Model>;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Mapping
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| List of available authentication mapping. You must first define them
|
||||
| inside the `contracts/auth.ts` file before mentioning them here.
|
||||
|
|
||||
*/
|
||||
const authConfig: AuthConfig = {
|
||||
guard: 'web',
|
||||
const authConfig = defineConfig({
|
||||
default: 'web',
|
||||
guards: {
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Web Guard
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Web guard uses classic old school sessions for authenticating users.
|
||||
| If you are building a standard web application, it is recommended to
|
||||
| use web guard with session driver
|
||||
|
|
||||
*/
|
||||
web: {
|
||||
driver: 'session',
|
||||
|
||||
provider: {
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Name of the driver
|
||||
|
|
||||
*/
|
||||
driver: 'lucid',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Identifier key
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The identifier key is the unique key on the model. In most cases specifying
|
||||
| the primary key is the right choice.
|
||||
|
|
||||
*/
|
||||
identifierKey: 'id',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Uids
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Uids are used to search a user against one of the mentioned columns. During
|
||||
| login, the auth module will search the user mentioned value against one
|
||||
| of the mentioned columns to find their user record.
|
||||
|
|
||||
*/
|
||||
uids: ['email'],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Model
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The model to use for fetching or finding users. The model is imported
|
||||
| lazily since the config files are read way earlier in the lifecycle
|
||||
| of booting the app and the models may not be in a usable state at
|
||||
| that time.
|
||||
|
|
||||
*/
|
||||
model: () => import('App/Models/User'),
|
||||
},
|
||||
},
|
||||
web: sessionGuard({
|
||||
useRememberMeTokens: false,
|
||||
provider: sessionUserProvider({
|
||||
model: () => import('#app/Models/User'),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export default authConfig;
|
||||
|
||||
/**
|
||||
* 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>;
|
||||
// };
|
||||
// }
|
||||
|
||||
interface Authenticators extends InferAuthenticators<typeof authConfig> {}
|
||||
|
||||
// const PROVIDER_REAL_USER: unique symbol;
|
||||
// export type SessionGuardUser<RealUser> = {
|
||||
// getId(): string | number | BigInt;
|
||||
// getOriginal(): RealUser;
|
||||
// };
|
||||
|
||||
// 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>;
|
||||
// }
|
||||
}
|
||||
|
||||
// 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>;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue