Skip to content

Commit fa36765

Browse files
committed
improve auth structure and add necessary auth/identity fixes
1 parent 5ea4aae commit fa36765

File tree

18 files changed

+401
-453
lines changed

18 files changed

+401
-453
lines changed

apps/events/src/components/auth.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Identity } from '@graphprotocol/hypergraph';
22
import { PrivyProvider, usePrivy, useWallets } from '@privy-io/react-auth';
3-
import { useRouter } from '@tanstack/react-router';
43
import { useEffect, useState } from 'react';
54

65
function DoGraphLogin() {
@@ -47,7 +46,8 @@ function Auth({ children }: { children: React.ReactNode }) {
4746
{children}
4847
</Identity.GraphLogin>
4948
) : (
50-
children
49+
// @ts-expect-error signer is not required should be fixed in GraphLogin
50+
<Identity.GraphLogin storage={localStorage}>{children}</Identity.GraphLogin>
5151
)}
5252
</>
5353
);
@@ -75,16 +75,3 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
7575
</PrivyProvider>
7676
);
7777
}
78-
79-
export function RequireAuth({ children }: { children: React.ReactNode }) {
80-
const { authenticated } = usePrivy();
81-
const { authenticated: graphAuthenticated } = Identity.useGraphLogin();
82-
const router = useRouter();
83-
if (!authenticated || !graphAuthenticated) {
84-
router.navigate({
85-
to: '/login',
86-
});
87-
return <div />;
88-
}
89-
return <>{children}</>;
90-
}

apps/events/src/components/debug-invitations.tsx

Lines changed: 0 additions & 33 deletions
This file was deleted.

apps/events/src/components/debug-space-events.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.

apps/events/src/components/debug-space-state.tsx

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { store, useGraphFramework, useSelector } from '@graphprotocol/hypergraph';
2+
import { useEffect, useState } from 'react';
3+
import { Button } from './ui/button';
4+
5+
export function DevTool({ spaceId }: { spaceId: string }) {
6+
const [isOpen, setIsOpen] = useState(false);
7+
8+
const spaces = useSelector(store, (state) => state.context.spaces);
9+
const updatesInFlight = useSelector(store, (state) => state.context.updatesInFlight);
10+
const { subscribeToSpace, isLoading } = useGraphFramework();
11+
12+
useEffect(() => {
13+
if (!isLoading) {
14+
subscribeToSpace({ spaceId });
15+
}
16+
}, [isLoading, subscribeToSpace, spaceId]);
17+
18+
const space = spaces.find((space) => space.id === spaceId);
19+
20+
return (
21+
<>
22+
<div className="flex flex-row gap-2">
23+
<Button
24+
onClick={(event) => {
25+
event.preventDefault();
26+
setIsOpen(!isOpen);
27+
}}
28+
>
29+
Hypergraph DevTool
30+
</Button>
31+
</div>
32+
{isOpen && !space && <div>Space not found</div>}
33+
{isOpen && space && (
34+
<>
35+
<h3>Space id: {space.id}</h3>
36+
<p>Keys:</p>
37+
<pre className="text-xs">{JSON.stringify(space.keys)}</pre>
38+
<br />
39+
<h3>Last update clock: {space.lastUpdateClock}</h3>
40+
<h3>Updates in flight</h3>
41+
<ul className="text-xs">
42+
{updatesInFlight.map((updateInFlight) => {
43+
return (
44+
<li key={updateInFlight} className="border border-gray-300">
45+
{updateInFlight}
46+
</li>
47+
);
48+
})}
49+
</ul>
50+
<hr />
51+
<h3>State</h3>
52+
<div className="text-xs">
53+
<pre>{JSON.stringify(space.state, null, 2)}</pre>
54+
</div>
55+
<hr />
56+
<h3>Events</h3>
57+
<ul className="text-xs">
58+
{space.events.map((event) => {
59+
return (
60+
<li key={event.transaction.id} className="border border-gray-300">
61+
<pre>{JSON.stringify(event, null, 2)}</pre>
62+
</li>
63+
);
64+
})}
65+
</ul>
66+
</>
67+
)}
68+
</>
69+
);
70+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import { Todo } from '../schema';
66
import { Button } from './ui/button';
77
import { Input } from './ui/input';
88

9-
export const TodosApp = () => {
9+
export const Todos = () => {
1010
const todos = Schema.useQuery(Todo);
1111
const createEntity = Schema.useCreateEntity(Todo);
1212
const updateEntity = Schema.useUpdateEntity(Todo);
1313
const deleteEntity = Schema.useDeleteEntity();
1414
const [newTodoTitle, setNewTodoTitle] = useState('');
1515

1616
return (
17-
<div>
18-
<h1>Todos</h1>
17+
<>
18+
<h1 className="text-2xl font-bold">Todos</h1>
1919
<div className="flex flex-row gap-2">
2020
<Input type="text" value={newTodoTitle} onChange={(e) => setNewTodoTitle(e.target.value)} />
2121
<Button
@@ -38,6 +38,6 @@ export const TodosApp = () => {
3838
<Button onClick={() => deleteEntity(todo.id)}>Delete</Button>
3939
</div>
4040
))}
41-
</div>
41+
</>
4242
);
4343
};

apps/events/src/components/user.tsx

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
export const availableAccounts: Array<{
2+
accountId: string;
3+
signaturePublicKey: string;
4+
signaturePrivateKey: string;
5+
encryptionPrivateKey: string;
6+
encryptionPublicKey: string;
7+
sessionToken: string;
8+
}> = [
9+
{
10+
accountId: '0x098B742F2696AFC37724887cf999e1cFdB8f4b55',
11+
signaturePublicKey: '0x0262701b2eb1b6b37ad03e24445dfcad1b91309199e43017b657ce2604417c12f5',
12+
signaturePrivateKey: '0x88bb6f20de8dc1787c722dc847f4cf3d00285b8955445f23c483d1237fe85366',
13+
encryptionPrivateKey: '0xbbf164a93b0f78a85346017fa2673cf367c64d81b1c3d6af7ad45e308107a812',
14+
encryptionPublicKey: '0x595e1a6b0bb346d83bc382998943d2e6d9210fd341bc8b9f41a7229eede27240',
15+
sessionToken: '0xdeadbeef1',
16+
},
17+
{
18+
accountId: '0x560436B2d3EE2d464D2756b7ebd6880CC5146614',
19+
signaturePublicKey: '0x03bf5d2a1badf15387b08a007d1a9a13a9bfd6e1c56f681e251514d9ba10b57462',
20+
signaturePrivateKey: '0x1eee32d3bc202dcb5d17c3b1454fb541d2290cb941860735408f1bfe39e7bc15',
21+
encryptionPrivateKey: '0xb32478dc6f40482127a09d0f1cabbf45dc83ebce638d6246f5552191009fda2c',
22+
encryptionPublicKey: '0x0f4e22dc85167597af85cba85988770cd77c25d317f2b14a1f49a54efcbfae3f',
23+
sessionToken: '0xdeadbeef2',
24+
},
25+
{
26+
accountId: '0xd909b84c934f24F7c65dfa51be6b11e4c6eabB47',
27+
signaturePublicKey: '0x0351460706cf386282d9b6ebee2ccdcb9ba61194fd024345e53037f3036242e6a2',
28+
signaturePrivateKey: '0x434518a2c9a665a7c20da086232c818b6c1592e2edfeecab29a40cf5925ca8fe',
29+
encryptionPrivateKey: '0xaaf71397e44fc57b42eaad5b0869d1e0247b4a7f2fe9ec5cc00dec3815849e7a',
30+
encryptionPublicKey: '0xd494144358a610604c4ab453b442d014f2843772eed19be155dd9fc55fe8a332',
31+
sessionToken: '0xdeadbeef3',
32+
},
33+
];

apps/events/src/routeTree.gen.ts

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { createFileRoute } from '@tanstack/react-router'
1313
// Import Routes
1414

1515
import { Route as rootRoute } from './routes/__root'
16-
import { Route as PlaygroundImport } from './routes/playground'
1716
import { Route as IndexImport } from './routes/index'
1817
import { Route as SpaceSpaceIdImport } from './routes/space/$spaceId'
1918

@@ -29,12 +28,6 @@ const LoginLazyRoute = LoginLazyImport.update({
2928
getParentRoute: () => rootRoute,
3029
} as any).lazy(() => import('./routes/login.lazy').then((d) => d.Route))
3130

32-
const PlaygroundRoute = PlaygroundImport.update({
33-
id: '/playground',
34-
path: '/playground',
35-
getParentRoute: () => rootRoute,
36-
} as any)
37-
3831
const IndexRoute = IndexImport.update({
3932
id: '/',
4033
path: '/',
@@ -58,13 +51,6 @@ declare module '@tanstack/react-router' {
5851
preLoaderRoute: typeof IndexImport
5952
parentRoute: typeof rootRoute
6053
}
61-
'/playground': {
62-
id: '/playground'
63-
path: '/playground'
64-
fullPath: '/playground'
65-
preLoaderRoute: typeof PlaygroundImport
66-
parentRoute: typeof rootRoute
67-
}
6854
'/login': {
6955
id: '/login'
7056
path: '/login'
@@ -86,45 +72,40 @@ declare module '@tanstack/react-router' {
8672

8773
export interface FileRoutesByFullPath {
8874
'/': typeof IndexRoute
89-
'/playground': typeof PlaygroundRoute
9075
'/login': typeof LoginLazyRoute
9176
'/space/$spaceId': typeof SpaceSpaceIdRoute
9277
}
9378

9479
export interface FileRoutesByTo {
9580
'/': typeof IndexRoute
96-
'/playground': typeof PlaygroundRoute
9781
'/login': typeof LoginLazyRoute
9882
'/space/$spaceId': typeof SpaceSpaceIdRoute
9983
}
10084

10185
export interface FileRoutesById {
10286
__root__: typeof rootRoute
10387
'/': typeof IndexRoute
104-
'/playground': typeof PlaygroundRoute
10588
'/login': typeof LoginLazyRoute
10689
'/space/$spaceId': typeof SpaceSpaceIdRoute
10790
}
10891

10992
export interface FileRouteTypes {
11093
fileRoutesByFullPath: FileRoutesByFullPath
111-
fullPaths: '/' | '/playground' | '/login' | '/space/$spaceId'
94+
fullPaths: '/' | '/login' | '/space/$spaceId'
11295
fileRoutesByTo: FileRoutesByTo
113-
to: '/' | '/playground' | '/login' | '/space/$spaceId'
114-
id: '__root__' | '/' | '/playground' | '/login' | '/space/$spaceId'
96+
to: '/' | '/login' | '/space/$spaceId'
97+
id: '__root__' | '/' | '/login' | '/space/$spaceId'
11598
fileRoutesById: FileRoutesById
11699
}
117100

118101
export interface RootRouteChildren {
119102
IndexRoute: typeof IndexRoute
120-
PlaygroundRoute: typeof PlaygroundRoute
121103
LoginLazyRoute: typeof LoginLazyRoute
122104
SpaceSpaceIdRoute: typeof SpaceSpaceIdRoute
123105
}
124106

125107
const rootRouteChildren: RootRouteChildren = {
126108
IndexRoute: IndexRoute,
127-
PlaygroundRoute: PlaygroundRoute,
128109
LoginLazyRoute: LoginLazyRoute,
129110
SpaceSpaceIdRoute: SpaceSpaceIdRoute,
130111
}
@@ -140,17 +121,13 @@ export const routeTree = rootRoute
140121
"filePath": "__root.tsx",
141122
"children": [
142123
"/",
143-
"/playground",
144124
"/login",
145125
"/space/$spaceId"
146126
]
147127
},
148128
"/": {
149129
"filePath": "index.tsx"
150130
},
151-
"/playground": {
152-
"filePath": "playground.tsx"
153-
},
154131
"/login": {
155132
"filePath": "login.lazy.tsx"
156133
},

0 commit comments

Comments
 (0)