Skip to content

Commit a24f0b5

Browse files
committed
feat: add navigation
1 parent bbe71bc commit a24f0b5

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

app/lib/navigation.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Auth } from "@supabase/ui";
2+
import Link from "next/link";
3+
import React from "react";
4+
5+
export function Navigation() {
6+
const user = Auth.useUser();
7+
return (
8+
<div>
9+
SupaNews{" "}
10+
{user.user === null ? (
11+
<Link href="/login">login</Link>
12+
) : (
13+
<>
14+
<Link href="/account">account</Link>
15+
<Link href="/logout">logout</Link>
16+
</>
17+
)}
18+
</div>
19+
);
20+
}

app/lib/supabase.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Auth } from "@supabase/ui";
44

55
const SupabaseClientContext = React.createContext<SupabaseClient | null>(null);
66

7-
export function SupabaseProvider(props: { children: React.ReactElement }) {
7+
export function SupabaseProvider(props: { children: React.ReactNode }) {
88
const [client] = React.useState(() =>
99
createClient(
1010
process.env.NEXT_PUBLIC_SUPABASE_URL!,

app/lib/urql.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22
import { createClient, Provider } from "urql";
33
import { useSupabaseClient } from "./supabase";
44

5-
export function UrqlProvider(props: { children: React.ReactElement }) {
5+
export function UrqlProvider(props: { children: React.ReactNode }) {
66
const supabaseClient = useSupabaseClient();
77

88
function getHeaders(): Record<string, string> {

app/pages/_app.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import "../styles/globals.css";
22
import type { AppProps } from "next/app";
33
import { UrqlProvider } from "../lib/urql";
44
import { SupabaseProvider } from "../lib/supabase";
5+
import { Navigation } from "../lib/navigation";
56

67
function MyApp({ Component, pageProps }: AppProps) {
78
return (
89
<SupabaseProvider>
910
<UrqlProvider>
11+
<Navigation />
1012
<Component {...pageProps} />
1113
</UrqlProvider>
1214
</SupabaseProvider>

app/pages/logout.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from "react";
2+
import type { NextPage } from "next";
3+
import { Auth } from "@supabase/ui";
4+
import { useSupabaseClient } from "../lib/supabase";
5+
import { useRouter } from "next/router";
6+
7+
const LogOut: NextPage = () => {
8+
const supabaseClient = useSupabaseClient();
9+
const router = useRouter();
10+
11+
React.useEffect(() => {
12+
supabaseClient.auth.signOut().then(() => router.replace("/"));
13+
}, []);
14+
return null;
15+
};
16+
17+
export default LogOut;

0 commit comments

Comments
 (0)