mirror of
https://github.com/ArthurDanjou/artdanj-shortener.git
synced 2026-01-14 15:54:08 +01:00
Move auth methods to Auth controller
This commit is contained in:
40
app/Controllers/Http/AuthController.ts
Normal file
40
app/Controllers/Http/AuthController.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
|
||||
export default class AuthController {
|
||||
|
||||
public async login ({ request, auth, response }: HttpContextContract) {
|
||||
const email = request.input('email')
|
||||
const password = request.input('password')
|
||||
|
||||
const token = await auth.use('api').attempt(email, password, {
|
||||
expiresIn: '2 days'
|
||||
})
|
||||
return response.status(200).send({
|
||||
token: token.toJSON()
|
||||
})
|
||||
}
|
||||
|
||||
public async token ({ response, request, auth }: HttpContextContract) {
|
||||
const email = request.input('email')
|
||||
const password = request.input('password')
|
||||
const token = await auth.use('api').attempt(email, password)
|
||||
return response.status(200).send({
|
||||
token: token.toJSON()
|
||||
})
|
||||
}
|
||||
|
||||
public async logout ({ response, auth, i18n }: HttpContextContract) {
|
||||
await auth.use('api').revoke()
|
||||
return response.status(200).send({
|
||||
message: i18n.formatMessage('messages.logout')
|
||||
})
|
||||
}
|
||||
|
||||
public async me ({ response, auth }: HttpContextContract) {
|
||||
await auth.authenticate()
|
||||
return response.status(200).send({
|
||||
user: auth.user
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user