@easy-auth/middlewares
v1.0.13
Published
Node.js middleware and utility functions to interface with [easy-auth](https://ice-milo.com/easy-auth/docs).
Downloads
562
Readme
About
Node.js middleware and utility functions to interface with easy-auth.
Installation
npm i @easy-auth/middlewares
yarn add @easy-auth/middlewares
Middleware
If your requests have the Ea-User-Token
header, you can use our middleware and utility functions to retrieve user information from them. If you do not provide your api-key to the middleware, the Ea-Api-Key
header from your requests will be used as a fallback. Both user-token and api-key are required to retrieve user information.
import { getEasyAuthUser, withEasyAuthContext } from "@easy-auth/middlewares";
import express from "express";
const app = express();
app.use(withEasyAuthContext("your-api-key"));
app.get("/user", async (req, res) => {
const user = await getEasyAuthUser(req);
res.status(200).json({ user });
});
app.listen(8080, () => console.info(`Server listening on port 8080`));
The user object will have the following shape:
interface EasyAuthUser {
id: string;
provider: "Google" | "Facebook";
providerId: string;
domain: string;
username: string;
createdAt: number; // unix epoch time
contents: Record<string, any>;
}