From 096143cd5da70f4f47151c737dbd5b67cee27ef1 Mon Sep 17 00:00:00 2001 From: Arthur Danjou Date: Thu, 10 Jun 2021 19:04:25 +0200 Subject: [PATCH] Working with auth --- app/Controllers/Http/LinksController.ts | 5 +- config/auth.ts | 63 +------------------------ contracts/auth.ts | 13 ----- 3 files changed, 4 insertions(+), 77 deletions(-) diff --git a/app/Controllers/Http/LinksController.ts b/app/Controllers/Http/LinksController.ts index 0b1a71a..15c33a0 100644 --- a/app/Controllers/Http/LinksController.ts +++ b/app/Controllers/Http/LinksController.ts @@ -1,7 +1,7 @@ import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext' import StoreValidator from "App/Validators/StoreValidator"; -import Link from "App/Models/Link"; import UpdateValidator from "App/Validators/UpdateValidator"; +import Link from "App/Models/Link"; export default class LinksController { @@ -39,7 +39,8 @@ export default class LinksController { } } - public async createLink ({request}: HttpContextContract) { + public async createLink ({request, auth}: HttpContextContract) { + await auth.authenticate() const link = await Link.create(await request.validate(StoreValidator)) return { message: `Link successfully created : ${link.code} + ${link.target}` diff --git a/config/auth.ts b/config/auth.ts index 557179b..1209c01 100644 --- a/config/auth.ts +++ b/config/auth.ts @@ -17,69 +17,8 @@ import { AuthConfig } from '@ioc:Adonis/Addons/Auth' | */ const authConfig: AuthConfig = { - guard: 'web', + guard: 'api', 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'), - }, - }, /* |-------------------------------------------------------------------------- | OAT Guard diff --git a/contracts/auth.ts b/contracts/auth.ts index a498628..90916e2 100644 --- a/contracts/auth.ts +++ b/contracts/auth.ts @@ -55,19 +55,6 @@ declare module '@ioc:Adonis/Addons/Auth' { | */ interface GuardsList { - /* - |-------------------------------------------------------------------------- - | Web Guard - |-------------------------------------------------------------------------- - | - | The web guard uses sessions for maintaining user login state. It uses - | the `user` provider for fetching user details. - | - */ - web: { - implementation: SessionGuardContract<'user', 'web'>, - config: SessionGuardConfig<'user'>, - }, /* |-------------------------------------------------------------------------- | OAT Guard