-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHeader.tsx
More file actions
62 lines (57 loc) · 1.93 KB
/
Header.tsx
File metadata and controls
62 lines (57 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { FunctionComponent } from "react";
import { useResource, useSolidAuth, useSubject } from "@ldo/solid-react";
import { SolidProfileShapeShapeType } from "./.ldo/solidProfile.shapeTypes";
const { Application } = require('@janeirodigital/interop-application');
const CLIENT_ID = 'http://localhost:3009/id.ttl';
export const Header: FunctionComponent = () => {
const { session, login, logout, fetch } = useSolidAuth();
const webIdResource = useResource(session.webId);
const profile = useSubject(SolidProfileShapeShapeType, session.webId);
let saiSession: unknown;
const loggedInName = webIdResource?.isReading()
? "LOADING..."
: profile?.fn
? profile.fn
: session.webId;
// let saiSession: unknown;
const saiAuth = async () => {
console.log('saiAuth');
// if (saiSession) return;
if (!session.webId) return;
const webId = session.webId as string;
const deps = { fetch, randomUUID: crypto.randomUUID.bind(crypto) };
saiSession = await Application.build(webId, CLIENT_ID, deps);
window.location.href = (saiSession as any).authorizationRedirectUri;
}
return (
<header>
{session.isLoggedIn ? (
// Is the session is logged in
<p>
You are logged as {loggedInName}.{" "}
<button onClick={logout}>Log Out</button>
<button onClick={saiAuth}>SAI Auth</button>
</p>
) : (
// If the session is not logged in
<p>
You are not Logged In{" "}
<button
onClick={() => {
// Get the Solid issuer the user should log into
const issuer = prompt(
"Enter your Solid Issuer",
"http://localhost:3000"
);
if (!issuer) return;
login(issuer, { clientId: CLIENT_ID });
}}
>
Log In
</button>
</p>
)}
<hr />
</header>
);
};