-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from chaitanyakole/revert-32-login_page_changes
Revert "Changes keycloak, login page and logout"
- Loading branch information
Showing
4 changed files
with
85 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,26 @@ | ||
import Keycloak from "keycloak-js"; | ||
|
||
let keycloakInstance: Keycloak | null = null; | ||
|
||
if (typeof window !== "undefined") { | ||
keycloakInstance = new Keycloak({ | ||
url: process.env.NEXT_PUBLIC_KEYCLOAK_URL || "", | ||
realm: process.env.NEXT_PUBLIC_KEYCLOAK_REALM || "", | ||
clientId: process.env.NEXT_PUBLIC_KEYCLOAK_CLIENT_ID || "", | ||
}); | ||
} | ||
|
||
export const initKeycloak = async (): Promise<boolean> => { | ||
if (!keycloakInstance) return false; | ||
|
||
try { | ||
const authenticated = await keycloakInstance.init({ | ||
onLoad: "login-required", | ||
silentCheckSsoRedirectUri: `${window.location.origin}/silent-check-sso.html`, | ||
}); | ||
|
||
if (authenticated) { | ||
localStorage.setItem("token", keycloakInstance.token || ""); | ||
localStorage.setItem("refreshToken", keycloakInstance.refreshToken || ""); | ||
const keycloakInstance = | ||
typeof window !== "undefined" | ||
? new Keycloak({ | ||
url: process.env.NEXT_PUBLIC_KEYCLOAK_URL || "", | ||
realm: process.env.NEXT_PUBLIC_KEYCLOAK_REALM || "", | ||
clientId: process.env.NEXT_PUBLIC_KEYCLOAK_CLIENT_ID || "", | ||
}) | ||
: null; | ||
export const logout = async () => { | ||
try { | ||
if (keycloakInstance) { | ||
await keycloakInstance.logout({ | ||
redirectUri: window.location.origin + "/login", | ||
}); | ||
localStorage.clear(); | ||
} | ||
|
||
return authenticated; | ||
} catch (error) { | ||
console.error("Keycloak initialization failed:", error); | ||
return false; | ||
} | ||
}; | ||
|
||
export const logout = async () => { | ||
if (!keycloakInstance) return; | ||
try { | ||
await keycloakInstance.logout({ | ||
redirectUri: window.location.origin + "/login", | ||
}); | ||
localStorage.clear(); | ||
} catch (error) { | ||
console.error("Logout failed:", error); | ||
} | ||
}; | ||
|
||
export default keycloakInstance; | ||
export default keycloakInstance; |