File tree Expand file tree Collapse file tree 5 files changed +41
-2
lines changed Expand file tree Collapse file tree 5 files changed +41
-2
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { Auth } from "@supabase/ui";
4
4
5
5
const SupabaseClientContext = React . createContext < SupabaseClient | null > ( null ) ;
6
6
7
- export function SupabaseProvider ( props : { children : React . ReactElement } ) {
7
+ export function SupabaseProvider ( props : { children : React . ReactNode } ) {
8
8
const [ client ] = React . useState ( ( ) =>
9
9
createClient (
10
10
process . env . NEXT_PUBLIC_SUPABASE_URL ! ,
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import React from "react";
2
2
import { createClient , Provider } from "urql" ;
3
3
import { useSupabaseClient } from "./supabase" ;
4
4
5
- export function UrqlProvider ( props : { children : React . ReactElement } ) {
5
+ export function UrqlProvider ( props : { children : React . ReactNode } ) {
6
6
const supabaseClient = useSupabaseClient ( ) ;
7
7
8
8
function getHeaders ( ) : Record < string , string > {
Original file line number Diff line number Diff line change @@ -2,11 +2,13 @@ import "../styles/globals.css";
2
2
import type { AppProps } from "next/app" ;
3
3
import { UrqlProvider } from "../lib/urql" ;
4
4
import { SupabaseProvider } from "../lib/supabase" ;
5
+ import { Navigation } from "../lib/navigation" ;
5
6
6
7
function MyApp ( { Component, pageProps } : AppProps ) {
7
8
return (
8
9
< SupabaseProvider >
9
10
< UrqlProvider >
11
+ < Navigation />
10
12
< Component { ...pageProps } />
11
13
</ UrqlProvider >
12
14
</ SupabaseProvider >
Original file line number Diff line number Diff line change
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 ;
You can’t perform that action at this time.
0 commit comments