Skip to content

Commit de0d153

Browse files
pranavdaanikgraf
andauthored
Change Geo Login flow in React-Vite and NextJs to not show Login when already logged in (#522)
Co-authored-by: Nik Graf <[email protected]>
1 parent 8d02db8 commit de0d153

File tree

3 files changed

+76
-17
lines changed

3 files changed

+76
-17
lines changed

.changeset/lazy-birds-wait.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"create-hypergraph": patch
3+
---
4+
5+
improve geo connect box based on authentication state in all templates
6+

apps/template-nextjs/app/page.tsx

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1+
'use client';
2+
3+
import { useHypergraphApp, useHypergraphAuth } from '@graphprotocol/hypergraph-react';
14
import Image from 'next/image';
25
import Link from 'next/link';
36

4-
import { LoginButton } from '@/Components/Login/LoginButton';
57
import { Button } from '@/Components/ui/button';
68

79
export default function HomePage() {
10+
const { redirectToConnect } = useHypergraphApp();
11+
const { authenticated } = useHypergraphAuth();
12+
13+
const handleSignIn = () => {
14+
redirectToConnect({
15+
storage: localStorage,
16+
connectUrl: 'https://connect.geobrowser.io/',
17+
successUrl: `${window.location.origin}/authenticate-success`,
18+
redirectFn: (url: URL) => {
19+
window.location.href = url.toString();
20+
},
21+
});
22+
};
23+
824
return (
925
<div className="container mx-auto px-4 py-8">
1026
<div className="text-center mb-12">
@@ -25,6 +41,7 @@ export default function HomePage() {
2541
fill="none"
2642
stroke="currentColor"
2743
viewBox="0 0 24 24"
44+
aria-hidden="true"
2845
>
2946
<path
3047
strokeLinecap="round"
@@ -46,7 +63,7 @@ export default function HomePage() {
4663
</div>
4764
</div>
4865

49-
{/* Section 2: Sign in with Geo Connect */}
66+
{/* Section 2: Conditional content based on authentication */}
5067
<div className="bg-white dark:bg-gray-800 rounded-lg p-6 shadow-lg border border-gray-200 dark:border-gray-700">
5168
<div className="text-center">
5269
<div className="w-12 h-12 bg-gray-100 dark:bg-gray-800 rounded-lg flex items-center justify-center mx-auto mb-4">
@@ -55,6 +72,7 @@ export default function HomePage() {
5572
fill="none"
5673
stroke="currentColor"
5774
viewBox="0 0 24 24"
75+
aria-hidden="true"
5876
>
5977
<path
6078
strokeLinecap="round"
@@ -64,11 +82,27 @@ export default function HomePage() {
6482
/>
6583
</svg>
6684
</div>
67-
<h3 className="text-xl font-semibold mb-3">Manage Your Data</h3>
68-
<p className="text-gray-600 dark:text-gray-300 mb-4">
69-
Sign in with Geo Connect to manage your private data and publish it to the public Knowledge Graph.
70-
</p>
71-
<LoginButton />
85+
{authenticated ? (
86+
<>
87+
<h3 className="text-xl font-semibold mb-3">Go to Geo Connect</h3>
88+
<p className="text-gray-600 dark:text-gray-300 mb-4">
89+
Go to Geo Connect to manage your private data and publish it to the public Knowledge Graph.
90+
</p>
91+
<Button onClick={handleSignIn} className="w-full bg-primary hover:bg-primary/90">
92+
Go to Geo Connect
93+
</Button>
94+
</>
95+
) : (
96+
<>
97+
<h3 className="text-xl font-semibold mb-3">Manage Your Data</h3>
98+
<p className="text-gray-600 dark:text-gray-300 mb-4">
99+
Sign in with Geo Connect to manage your private data and publish it to the public Knowledge Graph.
100+
</p>
101+
<Button onClick={handleSignIn} className="w-full bg-primary hover:bg-primary/90">
102+
Sign in with Geo Connect
103+
</Button>
104+
</>
105+
)}
72106
</div>
73107
</div>
74108

@@ -81,6 +115,7 @@ export default function HomePage() {
81115
fill="none"
82116
stroke="currentColor"
83117
viewBox="0 0 24 24"
118+
aria-hidden="true"
84119
>
85120
<path
86121
strokeLinecap="round"

apps/template-vite-react/src/routes/index.tsx

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { Button } from '@/components/ui/button';
2-
import { useHypergraphApp } from '@graphprotocol/hypergraph-react';
3-
import { Link, createFileRoute } from '@tanstack/react-router';
2+
import { useHypergraphApp, useHypergraphAuth } from '@graphprotocol/hypergraph-react';
3+
import { createFileRoute, Link } from '@tanstack/react-router';
44

55
export const Route = createFileRoute('/')({
66
component: Index,
77
});
88

99
function Index() {
1010
const { redirectToConnect } = useHypergraphApp();
11+
const { authenticated } = useHypergraphAuth();
1112

1213
const handleSignIn = () => {
1314
redirectToConnect({
@@ -40,6 +41,7 @@ function Index() {
4041
fill="none"
4142
stroke="currentColor"
4243
viewBox="0 0 24 24"
44+
aria-hidden="true"
4345
>
4446
<path
4547
strokeLinecap="round"
@@ -61,7 +63,7 @@ function Index() {
6163
</div>
6264
</div>
6365

64-
{/* Section 2: Sign in with Geo Connect */}
66+
{/* Section 2: Conditional content based on authentication */}
6567
<div className="bg-white dark:bg-gray-800 rounded-lg p-6 shadow-lg border border-gray-200 dark:border-gray-700">
6668
<div className="text-center">
6769
<div className="w-12 h-12 bg-gray-100 dark:bg-gray-800 rounded-lg flex items-center justify-center mx-auto mb-4">
@@ -70,6 +72,7 @@ function Index() {
7072
fill="none"
7173
stroke="currentColor"
7274
viewBox="0 0 24 24"
75+
aria-hidden="true"
7376
>
7477
<path
7578
strokeLinecap="round"
@@ -79,13 +82,27 @@ function Index() {
7982
/>
8083
</svg>
8184
</div>
82-
<h3 className="text-xl font-semibold mb-3">Manage Your Data</h3>
83-
<p className="text-gray-600 dark:text-gray-300 mb-4">
84-
Sign in with Geo Connect to manage your private data and publish it to the public Knowledge Graph.
85-
</p>
86-
<Button onClick={handleSignIn} className="w-full bg-primary hover:bg-primary/90">
87-
Sign in with Geo Connect
88-
</Button>
85+
{authenticated ? (
86+
<>
87+
<h3 className="text-xl font-semibold mb-3">Go to Geo Connect</h3>
88+
<p className="text-gray-600 dark:text-gray-300 mb-4">
89+
Go to Geo Connect to manage your private data and publish it to the public Knowledge Graph.
90+
</p>
91+
<Button onClick={handleSignIn} className="w-full bg-primary hover:bg-primary/90">
92+
Go to Geo Connect
93+
</Button>
94+
</>
95+
) : (
96+
<>
97+
<h3 className="text-xl font-semibold mb-3">Manage Your Data</h3>
98+
<p className="text-gray-600 dark:text-gray-300 mb-4">
99+
Sign in with Geo Connect to manage your private data and publish it to the public Knowledge Graph.
100+
</p>
101+
<Button onClick={handleSignIn} className="w-full bg-primary hover:bg-primary/90">
102+
Sign in with Geo Connect
103+
</Button>
104+
</>
105+
)}
89106
</div>
90107
</div>
91108

@@ -98,6 +115,7 @@ function Index() {
98115
fill="none"
99116
stroke="currentColor"
100117
viewBox="0 0 24 24"
118+
aria-hidden="true"
101119
>
102120
<path
103121
strokeLinecap="round"

0 commit comments

Comments
 (0)