Closed ilyahal closed 6 years ago
This is 'expected' behaviour - your logout function needs to invalidate the token rather than unauthenticating the user. Doing that is for the sessions authentication
How can I invalidate the token in logoutHandler(_:)?
Get the token from the request and delete it from the database. Next time a user uses that token it will be invalid and they'll get a 401
Thank you!
func logoutHandler(_ request: Request) throws -> Future<HTTPStatus> {
let token = try request.requireAuthenticated(Token.self)
return token.delete(on: request).transform(to: .ok)
}
Protected routes can still be hit after calling
unauthenticate(_:)
Steps to reproduce
Configurate:
Models:
Controller:
Steps:
POST /users
POST /users/login
DELETE /users
DELETE /users
Expected behavior
401 Unauthorized
Actual behavior
200 OK
Environment