mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
FIEF NextJS
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import "./styles/globals.scss";
|
||||
import { Roboto } from "next/font/google";
|
||||
import { Metadata } from "next";
|
||||
import { FiefAuthProvider } from "@fief/fief/nextjs/react";
|
||||
|
||||
const roboto = Roboto({ subsets: ["latin"], weight: "400" });
|
||||
|
||||
@@ -50,10 +51,14 @@ export const metadata: Metadata = {
|
||||
|
||||
export default function RootLayout({ children }) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body className={roboto.className + " flex flex-col min-h-screen"}>
|
||||
{children}
|
||||
</body>
|
||||
</html>
|
||||
<FiefAuthProvider currentUserPath="/api/current-user">
|
||||
{" "}
|
||||
{}
|
||||
<html lang="en">
|
||||
<body className={roboto.className + " flex flex-col min-h-screen"}>
|
||||
{children}
|
||||
</body>
|
||||
</html>
|
||||
</FiefAuthProvider>
|
||||
);
|
||||
}
|
||||
|
||||
46
www/app/lib/fief.ts
Normal file
46
www/app/lib/fief.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Fief, FiefUserInfo } from "@fief/fief";
|
||||
import { FiefAuth, IUserInfoCache } from "@fief/fief/nextjs";
|
||||
|
||||
export const SESSION_COOKIE_NAME = "reflector-auth";
|
||||
|
||||
export const fiefClient = new Fief({
|
||||
baseURL: process.env.FIEF_URL ?? "",
|
||||
clientId: process.env.FIEF_CLIENT_ID ?? "",
|
||||
clientSecret: process.env.FIEF_CLIENT_SECRET ?? "",
|
||||
});
|
||||
|
||||
class MemoryUserInfoCache implements IUserInfoCache {
|
||||
private storage: Record<string, any>;
|
||||
|
||||
constructor() {
|
||||
this.storage = {};
|
||||
}
|
||||
|
||||
async get(id: string): Promise<FiefUserInfo | null> {
|
||||
const userinfo = this.storage[id];
|
||||
if (userinfo) {
|
||||
return userinfo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async set(id: string, userinfo: FiefUserInfo): Promise<void> {
|
||||
this.storage[id] = userinfo;
|
||||
}
|
||||
|
||||
async remove(id: string): Promise<void> {
|
||||
this.storage[id] = undefined;
|
||||
}
|
||||
|
||||
async clear(): Promise<void> {
|
||||
this.storage = {};
|
||||
}
|
||||
}
|
||||
|
||||
export const fiefAuth = new FiefAuth({
|
||||
client: fiefClient,
|
||||
sessionCookieName: SESSION_COOKIE_NAME,
|
||||
redirectURI: "http://localhost:3000/auth-callback",
|
||||
logoutRedirectURI: "http://localhost:3000",
|
||||
userInfoCache: new MemoryUserInfoCache(),
|
||||
});
|
||||
Reference in New Issue
Block a user