Skip to content
Snippets Groups Projects
Commit 7988a804 authored by Cristian Schuszter's avatar Cristian Schuszter
Browse files

Add user info

parent 5c26d451
Branches master
No related tags found
No related merge requests found
import React from "react";
import React, { useEffect, useState } from "react";
import { connect } from "react-redux";
import {
keycloakAuthenticated,
......@@ -12,6 +12,21 @@ const App = ({ authenticated, userToken, kcInstance }) => {
kcInstance.logout();
};
const [userInfo, setUserInfo] = useState({});
useEffect(() => {
const getData = async () => {
const userInfoResponse = await fetch(
`${userToken.iss}/protocol/openid-connect/userinfo`,
{
headers: { Authorization: `Bearer ${kcInstance.token}` },
}
);
setUserInfo(await userInfoResponse.json());
};
getData();
}, [userToken, kcInstance.token]);
return (
<div className="App" style={{ margin: "20px" }}>
{!authenticated && <p>Loading...</p>}
......@@ -30,6 +45,13 @@ const App = ({ authenticated, userToken, kcInstance }) => {
{JSON.stringify(userToken, null, 2)}
</code>
</div>
<hr />
<p>My user info: </p>
<div>
<code style={{ whiteSpace: "pre-wrap" }}>
{JSON.stringify(userInfo, null, 2)}
</code>
</div>
</>
)}
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment