0.3.1 • Published 9 months ago
@hereya/auth-proxy-client-next v0.3.1
OIDC AUTH PROXY CLIENT
Companion client library for integrating oidc auth proxy DReAM webapp_deploy package in a Next.js application using App Router.
Installation
npm install @hereya/auth-proxy-client-next
Usage
- Protecting a page and getting user
import { AuthProxyClient } from '@hereya/auth-proxy-client-next';
const proxy = new AuthProxyClient();
export default async function Home() {
const user = await proxy.getUser()
return (
<main>
<h3>Welcome {user.name}</h3>
<div>
<a href="/auth/logout"> Logout </a>
</div>
</main>
)
}
- Emitting an authenticated request
import { AuthProxyClient } from '@hereya/auth-proxy-client-next';
const proxy = new AuthProxyClient();
export default async function Greeting() {
const data = await proxy.request(
process.env.API_URL!, {}, '/greeting'
).then(response => response.json())
return (
<main className="flex min-h-screen flex-col items-center p-24 space-y-8">
<h2 className="text-4xl font-bold text-center">
Greeting
</h2>
<p className="text-2xl font-bold text-center">
{data.message}
</p>
</main>
)
}