https://github.com/portier/portier-node
Portier client for Node.js
https://github.com/portier/portier-node
Last synced: about 2 months ago
JSON representation
Portier client for Node.js
- Host: GitHub
- URL: https://github.com/portier/portier-node
- Owner: portier
- License: mit
- Created: 2016-10-27T13:16:51.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-12-19T10:34:05.000Z (about 1 year ago)
- Last Synced: 2025-04-09T09:19:02.541Z (11 months ago)
- Language: TypeScript
- Size: 95.7 KB
- Stars: 48
- Watchers: 8
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-repositories - portier/portier-node - Portier client for Node.js (TypeScript)
README
# portier-node
A [Portier] client library for Node.js
[portier]: https://portier.github.io/
### Example
```js
import Fastify from "fastify";
import formPlugin from "@fastify/formbody";
import PortierClient from "portier";
const portier = new PortierClient({
redirectUri: "http://localhost:8000/verify",
});
const app = Fastify();
app.register(formPlugin);
app.get("/", (req, res) => {
res.type("text/html");
return `
Enter your email address:
Login
`;
});
app.post("/auth", async (req, res) => {
const authUrl = await portier.authenticate(req.body.email);
res.redirect(303, authUrl);
});
app.post("/verify", async (req, res) => {
if (req.body.error) {
res.type("text/html");
return `
Error: ${req.body.error_description}
`;
}
const email = await portier.verify(req.body.id_token);
res.type("text/html");
return `
Verified email address ${email}!
`;
});
app.listen({ port: 8000 });
```