1.0.4 • Published 3 years ago

@triszt4n/remark-auth v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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.

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago