0.7.0 • Published 5 months ago

portier v0.7.0

Weekly downloads
13
License
MIT
Repository
github
Last release
5 months ago

portier-node

A Portier client library for Node.js

Example

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 `
    <p>Enter your email address:</p>
    <form method="post" action="/auth">
      <input name="email" type="email">
      <button type="submit">Login</button>
    </form>
  `;
});

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 `
      <p>Error: ${req.body.error_description}</p>
    `;
  }

  const email = await portier.verify(req.body.id_token);

  res.type("text/html");
  return `
    <p>Verified email address ${email}!</p>
  `;
});

app.listen({ port: 8000 });
0.5.0

6 months ago

0.7.0

5 months ago

0.6.0

5 months ago

0.4.3

3 years ago

0.4.2

4 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago