Skip to content

Commit eafaff8

Browse files
removing all the unwanted files that were staged mistakenly by developerzohaib786 (#114)
1 parent fb0b517 commit eafaff8

3 files changed

Lines changed: 13 additions & 24 deletions

File tree

console/src/api/auth.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,10 @@ export const authApi = {
120120
},
121121

122122
logout: (): void => {
123-
localStorage.removeItem("polaris_access_token")
124-
localStorage.removeItem("polaris_realm")
123+
apiClient.clearAccessToken()
125124
// Use a small delay to allow toast to show before redirect
126125
setTimeout(() => {
127126
navigate("/login", true)
128127
}, 100)
129128
},
130-
}
131-
129+
}

console/src/api/client.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class ApiClient {
3333
private managementClient: AxiosInstance
3434
private catalogClient: AxiosInstance
3535
private polarisClient: AxiosInstance
36+
// Store access token in memory only (not in localStorage for security)
37+
private accessToken: string | null = null
3638

3739
constructor() {
3840
this.managementClient = axios.create({
@@ -63,7 +65,7 @@ class ApiClient {
6365
// Request interceptor to add auth token
6466
const requestInterceptor = (config: InternalAxiosRequestConfig) => {
6567
const token = this.getAccessToken()
66-
// Read realm from localStorage, fallback to environment variable for backward compatibility
68+
// Read realm from localStorage (non-sensitive configuration)
6769
const realm = localStorage.getItem("polaris_realm") || import.meta.env.VITE_POLARIS_REALM
6870

6971
if (token) {
@@ -107,16 +109,16 @@ class ApiClient {
107109
}
108110

109111
getAccessToken(): string | null {
110-
return localStorage.getItem("polaris_access_token")
112+
return this.accessToken
111113
}
112114

113115
clearAccessToken(): void {
114-
localStorage.removeItem("polaris_access_token")
116+
this.accessToken = null
115117
localStorage.removeItem("polaris_realm")
116118
}
117119

118120
setAccessToken(token: string): void {
119-
localStorage.setItem("polaris_access_token", token)
121+
this.accessToken = token
120122
}
121123

122124
getManagementClient(): AxiosInstance {
@@ -132,5 +134,4 @@ class ApiClient {
132134
}
133135
}
134136

135-
export const apiClient = new ApiClient()
136-
137+
export const apiClient = new ApiClient()

console/src/hooks/useAuth.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
import { createContext, useContext, useState, useEffect, type ReactNode } from "react"
20+
import { createContext, useContext, useState, type ReactNode } from "react"
2121
import { toast } from "sonner"
2222
import { authApi } from "@/api/auth"
2323

@@ -32,18 +32,11 @@ const AuthContext = createContext<AuthContextType | undefined>(undefined)
3232

3333
export function AuthProvider({ children }: { children: ReactNode }) {
3434
const [isAuthenticated, setIsAuthenticated] = useState<boolean>(false)
35-
const [loading, setLoading] = useState<boolean>(true)
36-
37-
useEffect(() => {
38-
// Check if user is already authenticated
39-
const token = localStorage.getItem("polaris_access_token")
40-
setIsAuthenticated(!!token)
41-
setLoading(false)
42-
}, [])
35+
const [loading] = useState<boolean>(false)
4336

4437
const login = async (clientId: string, clientSecret: string, realm: string) => {
4538
try {
46-
// Store realm in localStorage
39+
// Store realm in localStorage (non-sensitive configuration)
4740
if (realm) {
4841
localStorage.setItem("polaris_realm", realm)
4942
}
@@ -59,8 +52,6 @@ export function AuthProvider({ children }: { children: ReactNode }) {
5952
toast.success("Logged out successfully")
6053
authApi.logout()
6154
setIsAuthenticated(false)
62-
// Clear realm from localStorage on logout
63-
localStorage.removeItem("polaris_realm")
6455
}
6556

6657
return (
@@ -77,5 +68,4 @@ export function useAuth() {
7768
throw new Error("useAuth must be used within an AuthProvider")
7869
}
7970
return context
80-
}
81-
71+
}

0 commit comments

Comments
 (0)