+
Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

Client Side Rendering Architecture | Persist token problem #205

@gokhangunduz

Description

@gokhangunduz

Hello, I'm opening this issue because I couldn't solve a problem.

There is client rendering architecture in my project, so I use React but not Next and its alternatives. For this reason, I cannot use SSR.

My problem is, I want to be able to persist the token I got from keycloak, I want to use the token I persisted even though the page is reloaded. Because every time the page is reloaded, I have to acquire tokens again.

I am attaching the codes I used, thanks in advance for your interest.

keycloak.ts;

import Keycloak from "keycloak-js";

const keycloak = Keycloak({
  url: process.env.REACT_APP_KEYCLOAK_URL!,
  realm: process.env.REACT_APP_KEYCLOAK_REALM!,
  clientId: process.env.REACT_APP_KEYCLOAK_CLIENT_ID!,
});

export default keycloak;

index.tsx;

import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import { ReactKeycloakProvider } from "@react-keycloak/web";
import keycloak from "./auth/keycloak";
const root = ReactDOM.createRoot(
  document.getElementById("root") as HTMLElement
);

root.render(
  <ReactKeycloakProvider
    authClient={keycloak}
    autoRefreshToken={true}
  >
    <App />
  </ReactKeycloakProvider>
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载