worked on authController
This commit is contained in:
@@ -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')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user