Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add types to clients, make dev auth easier #73

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/auth-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { createClient } from "@/lib/database/server";
import { redirect } from "next/navigation";

export async function signIn() {
export async function signInWithDiscord() {
const supabase = createClient();

const { error, data } = await supabase.auth.signInWithOAuth({
Expand Down
10 changes: 5 additions & 5 deletions lib/components/structural/navbar/top-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ import {
SheetTrigger,
SheetContent,
} from "@components/ui/sheet";
import { Avatar, AvatarFallback } from "@components/ui/avatar";
import { Avatar, AvatarImage, AvatarFallback } from "@components/ui/avatar";
import { pageData } from "./nav-links";
import { ModeToggle } from "./toggle";
import { signIn } from "@/lib/auth-actions";
import { signInWithDiscord } from "@/lib/auth-actions";
import { createClient } from "@/lib/database/server";
import { AvatarImage } from "@radix-ui/react-avatar";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuTrigger,
} from "../../ui/dropdown-menu";
} from "@components/ui/dropdown-menu";
import Link from "next/link";
import { SignOut } from "./sign-out";
import { NavLink } from "./nav-link";

async function AuthManager() {
const supabase = createClient();

const {
data: { user },
} = await supabase.auth.getUser();
Expand Down Expand Up @@ -72,7 +72,7 @@ async function AuthManager() {
}

return (
<form action={signIn}>
<form action={signInWithDiscord}>
<Button variant="secondary">
<span>YETI Login</span>
</Button>
Expand Down
3 changes: 2 additions & 1 deletion lib/database/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createBrowserClient } from "@supabase/ssr";
import { Database } from "./types";

export function createClient() {
return createBrowserClient(
return createBrowserClient<Database>(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
);
Expand Down
3 changes: 2 additions & 1 deletion lib/database/server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { createServerClient } from "@supabase/ssr";
import { cookies } from "next/headers";
import { Database } from "./types";

export function createClient() {
const cookieStore = cookies();

return createServerClient(
return createServerClient<Database>(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
Expand Down
3 changes: 2 additions & 1 deletion lib/database/service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { createClient } from "@supabase/supabase-js";
import { Database } from "./types";

/**
* SHOULD ONLY EVER BE USED ON SERVER
*/
export function createServiceClient() {
return createClient(
return createClient<Database>(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.SUPABASE_SERVICE_KEY!,
{
Expand Down
Loading