streamlined auth-controller responses
This commit is contained in:
@@ -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(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
return response.forbidden(result)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user