auf-next

0.0.20 • Public • Published

Auf Auth Next

The Auf SDK for Next.js.

This library requires the JWT_SECRET_KEY environment variable.

JWT_SECRET_KEY=xyz

It can be generated using the code below:

openssl rand -base64 32

Create a route.js file.

// app/api/auf/route.js

import { fetchToken } from "auf-next";
import { NextResponse } from "next/server";

export async function GET(request) {
  const redirectUrl = await fetchToken(request);
  return NextResponse.redirect(redirectUrl);
}

Register the app on the Auf dashboard.

Use the registered appName in an AuthBtn component.

import { AuthBtn } from "auf-next";

<AuthBtn
  redirectUrl={
    process.env.NODE_ENV === "production"
      ? "https://my-site.com"
      : "http://localhost:3000"
  }
  appName="my-site"
  SignInComponent={<div className="btn">Sign in</div>}
  SignOutComponent={<div className="btn">Sign Out</div>}
/>;
import { AuthBtn } from "auf-next";

<AuthBtn
  redirectUrl={
    process.env.NODE_ENV === "production"
      ? "https://my-site.com"
      : "http://localhost:3000"
  }
  appName="my-site"
  SignInComponent={<div className="btn">Sign in</div>}
  SignedInComponent={
    <div className="btn">Show some content for the signed-in users</div>
  }
/>;
import { fetchCurrentUser } from "auf_next";

export default async function ShowCurrentUser() {
  const currentUser = await fetchCurrentUser();

  return (
    <div>
      <p>User ID: {currentUser.id}</p>
      <p>Email: {currentUser.email}</p>
      <p>Device ID: {currentUser.deviceId}</p>
      <p>App ID: {currentUser.appId}</p>
      <p>Roles: {currentUser.roles}</p>
    </div>
  );
}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.200latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.200
0.0.190
0.0.180
0.0.170
0.0.160
0.0.150
0.0.140
0.0.130
0.0.120
0.0.110
0.0.100
0.0.90
0.0.80
0.0.70
0.0.60
0.0.50
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i auf-next

Weekly Downloads

0

Version

0.0.20

License

ISC

Unpacked Size

11.9 kB

Total Files

20

Last publish

Collaborators

  • vitalyliber