added login / logout functionality and authorization rules via bouncer
This commit is contained in:
22
app/Controllers/Http/AuthController.ts
Normal file
22
app/Controllers/Http/AuthController.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
|
||||
export default class AuthController {
|
||||
|
||||
public async login({auth, request, response}: HttpContextContract) {
|
||||
const username = request.input('username')
|
||||
const password = request.input('password')
|
||||
|
||||
try {
|
||||
await auth.attempt(username, password)
|
||||
response.ok("Login successful")
|
||||
} catch (error) {
|
||||
return error
|
||||
}
|
||||
}
|
||||
|
||||
public async logout({auth, response}: HttpContextContract) {
|
||||
await auth.logout()
|
||||
|
||||
return response.ok('Logged out successfully')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user