Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/portier/portier-node

Portier client for Node.js
https://github.com/portier/portier-node

Last synced: 2 months ago
JSON representation

Portier client for Node.js

Awesome Lists containing this project

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 });
```