This commit is contained in:
Kiss Dávid
2026-03-21 12:34:22 +01:00
parent 465613f6a0
commit 9efbe5baee
42 changed files with 571 additions and 562 deletions
+13 -21
View File
@@ -4,13 +4,12 @@ import User from '#models/user'
import logger from '@adonisjs/core/services/logger'
export default class AuthController {
/**
* Registers a user using the provided email, password, and full name.
*
* @bodyParam *email* - string | The email of the user.
* @bodyParam *password* - string | The password of the user.
* @bodyParam *fullName* - string | The full name of the user.
*
* @bodyParam *email* - string | The email of the user.
* @bodyParam *password* - string | The password of the user.
* @bodyParam *fullName* - string | The full name of the user.
* @returns The user access token.
*/
async register({ request }: HttpContext) {
@@ -19,16 +18,15 @@ export default class AuthController {
const user = await User.create(data)
logger.info('User registered: %s, %s, %s', user.fullName, user.email, request.ip())
return User.accessTokens.create(user)
}
catch(error) {
logger.error('Registration failed: %s',error)
throw(error)
} catch (error) {
logger.error('Registration failed: %s', error)
throw error
}
}
/**
* Log in a user using the provided email and password.
*
*
* @bodyParam *email* - string | The email of the user.
* @bodyParam *password* - string | The password of the user.
* @returns The access token of the user.
@@ -39,17 +37,12 @@ export default class AuthController {
const user = await User.verifyCredentials(email, password)
logger.info('User logged in: %s', email)
return User.accessTokens.create(user)
}
catch(error) {
logger.error('Login failed: %s',error)
} catch (error) {
logger.error('Login failed: %s', error)
throw error
}
}
/**
* Deletes the user's access token and logs them out. If the user is not
* authenticated, returns an unauthorized message.
@@ -60,10 +53,9 @@ export default class AuthController {
try {
await User.accessTokens.delete(user, user.currentAccessToken.identifier)
return { message: 'User logged out' }
}
catch(error){
logger.error('Logout failed: %s',error)
throw(error)
} catch (error) {
logger.error('Logout failed: %s', error)
throw error
}
}