worked on authController

This commit is contained in:
Sockenklaus
2021-10-20 01:21:44 +02:00
parent 4d7f2efedb
commit 5173e8d4c9
5 changed files with 111 additions and 6 deletions

View File

@@ -1,16 +1,21 @@
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import Logger from '@ioc:Adonis/Core/Logger'
export default class AuthController {
public async login({auth, request, response}: HttpContextContract) {
const username = request.input('username')
const password = request.input('password')
const username = request.body().username
const password = request.body().password
try {
await auth.attempt(username, password)
response.ok("Login successful")
return response.ok({
Message: 'Login successful!',
user: auth.user?.username,
role: auth.user?.role
})
} catch (error) {
return error
return response.forbidden('Unauthorized')
}
}