Last active
January 28, 2019 06:50
-
-
Save timbaev/e01878c64903cc1f55ae1bcd03173ddb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import Vapor | |
import JWT | |
extension Request { | |
var token: String { | |
if let token = self.http.headers[.authorization].first { | |
return token | |
} else { | |
return "" | |
} | |
} | |
func authorizedUser() throws -> Future<User> { | |
let userID = try TokenHelpers.getUserID(fromPayloadOf: self.token) | |
return User.find(userID, on: self).unwrap(or: Abort(.unauthorized, reason: "Authorized user not found")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment