Skip to content

Commit

Permalink
feat: add navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Mar 24, 2022
1 parent bbe71bc commit a24f0b5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
20 changes: 20 additions & 0 deletions app/lib/navigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Auth } from "@supabase/ui";
import Link from "next/link";
import React from "react";

export function Navigation() {
const user = Auth.useUser();
return (
<div>
SupaNews{" "}
{user.user === null ? (
<Link href="/login">login</Link>
) : (
<>
<Link href="/account">account</Link>
<Link href="/logout">logout</Link>
</>
)}
</div>
);
}
2 changes: 1 addition & 1 deletion app/lib/supabase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Auth } from "@supabase/ui";

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

export function SupabaseProvider(props: { children: React.ReactElement }) {
export function SupabaseProvider(props: { children: React.ReactNode }) {
const [client] = React.useState(() =>
createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
Expand Down
2 changes: 1 addition & 1 deletion app/lib/urql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { createClient, Provider } from "urql";
import { useSupabaseClient } from "./supabase";

export function UrqlProvider(props: { children: React.ReactElement }) {
export function UrqlProvider(props: { children: React.ReactNode }) {
const supabaseClient = useSupabaseClient();

function getHeaders(): Record<string, string> {
Expand Down
2 changes: 2 additions & 0 deletions app/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import "../styles/globals.css";
import type { AppProps } from "next/app";
import { UrqlProvider } from "../lib/urql";
import { SupabaseProvider } from "../lib/supabase";
import { Navigation } from "../lib/navigation";

function MyApp({ Component, pageProps }: AppProps) {
return (
<SupabaseProvider>
<UrqlProvider>
<Navigation />
<Component {...pageProps} />
</UrqlProvider>
</SupabaseProvider>
Expand Down
17 changes: 17 additions & 0 deletions app/pages/logout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from "react";
import type { NextPage } from "next";
import { Auth } from "@supabase/ui";
import { useSupabaseClient } from "../lib/supabase";
import { useRouter } from "next/router";

const LogOut: NextPage = () => {
const supabaseClient = useSupabaseClient();
const router = useRouter();

React.useEffect(() => {
supabaseClient.auth.signOut().then(() => router.replace("/"));
}, []);
return null;
};

export default LogOut;

0 comments on commit a24f0b5

Please sign in to comment.