Created
May 14, 2019 15:13
-
-
Save ea2305/7354b0b9c3fe8fc859da47a471f5f123 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const Env = use('Env') | |
const Logger = use('Logger') | |
class AuthController { | |
/** | |
* Login user controller | |
* @param {Object} request : HTTP Request | |
* @param {Object} response : HTTP Request | |
*/ | |
async login ({ request, response, auth }) { | |
// get user request information | |
const filter = ['email', 'password'] | |
const { email, password } = request.only(filter) | |
try { | |
// Attemp login | |
const token = await auth.attempt(email, password) | |
// return token to client | |
return response.ok({ token: token.token, type: token.type }) | |
} catch (error) { | |
if (Env.get('Logger') == 'true') | |
Logger.error(error) | |
return response.unauthorized({ error: 'bad credentials' }) | |
} | |
} | |
} | |
module.exports = AuthController |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment