Skip to content

Commit 7dbd7d5

Browse files
committed
Use token directly from memory
1 parent 9b6e656 commit 7dbd7d5

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

src/keycloak.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ export const initKeycloak = async (): Promise<boolean> => {
2020
console.log("User is not authenticated")
2121
}
2222

23-
if (keycloak.token) {
24-
localStorage.setItem("token", keycloak.token)
25-
}
26-
2723
return authenticated
2824
} catch (error: unknown) {
2925
console.error("Failed to initialize adapter:", error instanceof Error ? error.message : String(error))

src/lib/api-client.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import { client as heyApiClient } from "@/generated/client/client.gen"
22
import * as sdk from "@/generated/client/sdk.gen"
3+
import keycloak from "../keycloak"
34

45
heyApiClient.setConfig({
56
baseUrl: import.meta.env.VITE_API_BASE_URL as string,
67
})
78

89
// Add the auth token interceptor
910
heyApiClient.interceptors.request.use((request) => {
10-
const token = localStorage.getItem("token")
11-
12-
if (token) {
11+
if (keycloak.token!) {
1312
let headers = request.headers
1413
if (!(headers instanceof Headers)) {
1514
headers = new Headers(headers as HeadersInit)
1615
}
17-
headers.set("Authorization", `Bearer ${token}`)
16+
headers.set("Authorization", `Bearer ${keycloak.token}`)
1817

1918
if (!(request.headers instanceof Headers)) {
2019
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any

src/main.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ function App() {
6767
}
6868

6969
void prepare().then(() => {
70-
// loadToken();
7170
createRoot(document.getElementById("root")!).render(
7271
<StrictMode>
7372
<App />

0 commit comments

Comments
 (0)