@triszt4n/remark-auth
v1.0.4
Published
Authorization functions for the Remark project by triszt4n
Downloads
1
Readme
remark-auth
Authorization functions for the Remark project by triszt4n.
It was easier to lift out the reusable code from the backend into an NPM package, so it the functions could be versioned and easily built with the Azure Functions (and for better performance).
Note for me: push to master with newer version specified in package.json to publish this package.
Usage
In your Azure Function when you want to read the user from the Authorization header, use this snippet:
// Authorization
const result = readUserFromAuthHeader(req, process.env.JWT_PRIVATE_KEY)
if (result.isError) {
context.res = {
// An example for how you might want to return with the error message
status: result.status,
body: { message: result.message }
}
return
}
const { userFromJwt } = result
If you want to create a token:
const jwtToken = createJWT(dbUser, process.env.JWT_PRIVATE_KEY, 60 * 60 * 24 * 2) // two days
Licence
MIT, see in LICENSE file.