0.0.21 • Published 9 months ago
auf-next v0.0.21
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>
);
}
0.0.21
9 months ago
0.0.20
12 months ago
0.0.17
12 months ago
0.0.18
12 months ago
0.0.19
12 months ago
0.0.10
12 months ago
0.0.11
12 months ago
0.0.12
12 months ago
0.0.13
12 months ago
0.0.14
12 months ago
0.0.15
12 months ago
0.0.9
12 months ago
0.0.16
12 months ago
0.0.8
12 months ago
0.0.5
12 months ago
0.0.4
12 months ago
0.0.7
12 months ago
0.0.6
12 months ago
0.0.3
1 year ago
0.0.2
1 year ago
0.0.1
1 year ago