Skip to content

Commit

Permalink
Expose token in KeycloakUserProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
gf-rog committed Mar 22, 2024
1 parent eecea12 commit 33fec8d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion frontend/src/helpers/KeycloakUserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function KeycloakUserProvider({ children }: { children: React.ReactNode }) {
const [socket, setSocket] = useState<Socket | null>(null);

const keycloakRef = useRef<Keycloak | null>(null);
const [token, setToken] = useState<string | undefined>()

const updateUserData = async () => {
const keycloak = keycloakRef.current!;
Expand Down Expand Up @@ -48,7 +49,10 @@ function KeycloakUserProvider({ children }: { children: React.ReactNode }) {
realm: "mercury",
clientId: "mercury-client",
});
keycloak.onAuthSuccess = () => updateUserData();
keycloak.onAuthSuccess = () => {
updateUserData();
setToken(keycloak.token)
}

keycloakRef.current = keycloak;
});
Expand Down Expand Up @@ -188,6 +192,7 @@ function KeycloakUserProvider({ children }: { children: React.ReactNode }) {
provider,
user,
userState,
token,
socket,
login,
redirectToLogin,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/helpers/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface UserContextValue {
provider: string;
user: User | null;
userState: UserState;
token?: string;
socket: Socket | null;
login: (mail: string, password: string) => Promise<void>;
redirectToLogin: () => void;
Expand Down

0 comments on commit 33fec8d

Please sign in to comment.