From 5c8c51dd9dfcb03c5f28b6ef1ae43da72818098b Mon Sep 17 00:00:00 2001 From: Sockenklaus Date: Mon, 25 Oct 2021 15:57:53 +0200 Subject: [PATCH] streamlined auth-controller responses --- app/Controllers/Http/AuthController.ts | 29 +++----------------------- database/seeders/User.ts | 7 +++++++ 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/app/Controllers/Http/AuthController.ts b/app/Controllers/Http/AuthController.ts index cb986a4..aa3bac7 100644 --- a/app/Controllers/Http/AuthController.ts +++ b/app/Controllers/Http/AuthController.ts @@ -5,22 +5,11 @@ import Database from '@ioc:Adonis/Lucid/Database' import { DateTime } from 'luxon' type AuthSuccResult = { - notification: { - type: string, - text: string - } user: string, role: string, token: string } -type AuthErrResult = { - notification: { - text: string, - type: string - } -} - export default class AuthController { @@ -34,10 +23,6 @@ export default class AuthController { const token = await auth.use('api').attempt(username, password) const result : AuthSuccResult = { - notification: { - type: 'success', - text: 'Login successful!' - }, user: auth.user?.username ?? '', role: auth.user?.role ?? '', token: token.token @@ -46,22 +31,14 @@ export default class AuthController { return response.ok(result) } catch (error) { - const result : AuthErrResult = { - notification: { - type: 'danger', - text: error.message - } - } - - return response.forbidden(result) + return response.forbidden(error.message) } } - public async logout({auth, response}: HttpContextContract) { - Logger.info("entering logout function") + public async logout({auth}: HttpContextContract) { try { await auth.use('api').revoke() - return response.ok('Logged out successfully') + return } catch(error) { Logger.error(error.message) diff --git a/database/seeders/User.ts b/database/seeders/User.ts index ce1ed11..00bb716 100644 --- a/database/seeders/User.ts +++ b/database/seeders/User.ts @@ -12,6 +12,13 @@ export default class UserSeeder extends BaseSeeder { email: 'test@test.de', isActive: true }) + await User.create({ + username: 'user', + password: 'user', + role: 'employee', + email: 'user@test.de', + isActive: true + }) } catch(error) { Logger.error(error.message)