Skip to content

Commit

Permalink
docs: decoding access token in example (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
aversini authored Aug 25, 2024
1 parent 62b55e4 commit 710fadf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
1 change: 1 addition & 0 deletions examples/code-flow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "biome lint src"
},
"dependencies": {
"@versini/auth-common": "workspace:../../packages/auth-common",
"@versini/auth-provider": "workspace:../../packages/auth-provider",
"@versini/ui-components": "5.21.2",
"@versini/ui-styles": "1.9.5",
Expand Down
14 changes: 10 additions & 4 deletions examples/code-flow/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { decodeToken } from "@versini/auth-common";
import { useAuth } from "@versini/auth-provider";
import { Button, Footer, Header, Main } from "@versini/ui-components";
import { Flexgrid, FlexgridItem } from "@versini/ui-system";
import { useEffect, useState } from "react";

export const App = ({ timeout }: { timeout: string }) => {
const [accessToken, setAccessToken] = useState("");
const [accessToken, setAccessToken] = useState<any>(null);
const {
login,
logout,
Expand Down Expand Up @@ -54,7 +55,9 @@ export const App = ({ timeout }: { timeout: string }) => {
}) => {
e.preventDefault();
const token = await getAccessToken();
setAccessToken(token);
if (token) {
setAccessToken(decodeToken(token));
}
};

const handleValidRegistration = async (e: {
Expand Down Expand Up @@ -129,7 +132,10 @@ export const App = ({ timeout }: { timeout: string }) => {
<FlexgridItem>
<Button
size="small"
onClick={logout}
onClick={() => {
setAccessToken(null);
logout();
}}
variant="danger"
disabled={!isAuthenticated}
>
Expand Down Expand Up @@ -160,7 +166,7 @@ export const App = ({ timeout }: { timeout: string }) => {
<h2>Access Token</h2>

<Button onClick={handleClickOnGetAccessToken}>get Access Token</Button>
<pre className="text-xs">{accessToken}</pre>
<pre className="text-xs">{JSON.stringify(accessToken, null, 2)}</pre>
</Main>
<Footer row1={<p>Timeout: {timeout}</p>} />
</div>
Expand Down
28 changes: 15 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 710fadf

Please sign in to comment.