feat(config): inject frontend runtime config
This commit is contained in:
@@ -9,16 +9,26 @@ type KeycloakTokenResponse = {
|
||||
refresh_token?: string;
|
||||
};
|
||||
|
||||
const keycloakIssuer = process.env.KEYCLOAK_ISSUER!;
|
||||
const keycloakClientId = process.env.KEYCLOAK_CLIENT_ID!;
|
||||
const keycloakClientSecret = process.env.KEYCLOAK_CLIENT_SECRET!;
|
||||
const keycloakTokenEndpoint = `${keycloakIssuer.replace(/\/$/, "")}/protocol/openid-connect/token`;
|
||||
const getKeycloakTokenEndpoint = () => {
|
||||
const issuer = process.env.KEYCLOAK_ISSUER;
|
||||
return issuer
|
||||
? `${issuer.replace(/\/$/, "")}/protocol/openid-connect/token`
|
||||
: undefined;
|
||||
};
|
||||
|
||||
const refreshAccessToken = async (token: JWT): Promise<JWT> => {
|
||||
if (!token.refreshToken) {
|
||||
return { ...token, error: "RefreshAccessTokenError" };
|
||||
}
|
||||
|
||||
const keycloakClientId = process.env.KEYCLOAK_CLIENT_ID;
|
||||
const keycloakClientSecret = process.env.KEYCLOAK_CLIENT_SECRET;
|
||||
const keycloakTokenEndpoint = getKeycloakTokenEndpoint();
|
||||
|
||||
if (!keycloakClientId || !keycloakClientSecret || !keycloakTokenEndpoint) {
|
||||
return { ...token, error: "RefreshAccessTokenError" };
|
||||
}
|
||||
|
||||
const body = new URLSearchParams({
|
||||
grant_type: "refresh_token",
|
||||
client_id: keycloakClientId,
|
||||
@@ -50,9 +60,9 @@ const authOptions: NextAuthOptions = {
|
||||
// Configure one or more authentication providers
|
||||
providers: [
|
||||
KeycloakProvider({
|
||||
clientId: keycloakClientId,
|
||||
clientSecret: keycloakClientSecret,
|
||||
issuer: keycloakIssuer,
|
||||
clientId: process.env.KEYCLOAK_CLIENT_ID ?? "",
|
||||
clientSecret: process.env.KEYCLOAK_CLIENT_SECRET ?? "",
|
||||
issuer: process.env.KEYCLOAK_ISSUER ?? "",
|
||||
profile(profile) {
|
||||
return {
|
||||
id: profile.sub,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { Metadata } from "next";
|
||||
import { cookies } from "next/headers";
|
||||
import Script from "next/script";
|
||||
import React, { Suspense } from "react";
|
||||
import { RefineContext } from "./RefineContext";
|
||||
import { META_DATA } from "@config/config";
|
||||
@@ -18,6 +19,7 @@ export default async function RootLayout({
|
||||
return (
|
||||
<html lang="en">
|
||||
<body>
|
||||
<Script src="/runtime-config.js" strategy="beforeInteractive" />
|
||||
<Suspense>
|
||||
<RefineContext defaultMode={defaultMode}>{children}</RefineContext>
|
||||
</Suspense>
|
||||
|
||||
Reference in New Issue
Block a user