Skip to content

Commit

Permalink
feat: use proper supabase client
Browse files Browse the repository at this point in the history
  • Loading branch information
Balastrong committed Aug 11, 2024
1 parent 1ac3dc6 commit 97489ae
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 26 deletions.
19 changes: 2 additions & 17 deletions src/app/auth/callback/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
GITHUB_REFRESH_TOKEN_COOKIE,
GITHUB_ACCESS_TOKEN_COOKIE,
} from "@/lib/supabase/cookies";
import { createClient } from "@/lib/supabase/server";
import { createServerClient } from "@supabase/ssr";
import { cookies } from "next/headers";
import { NextResponse } from "next/server";
Expand All @@ -14,23 +15,7 @@ export async function GET(request: Request) {

if (code) {
const cookieStore = cookies();
// TODO Isn't this the same as the createClient function?
const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
getAll() {
return cookieStore.getAll();
},
setAll(cookiesToSet) {
cookiesToSet.forEach(({ name, value, options }) =>
cookieStore.set(name, value, options),
);
},
},
},
);
const supabase = createClient();

supabase.auth.onAuthStateChange((event, session) => {
if (session && session.provider_token) {
Expand Down
7 changes: 3 additions & 4 deletions src/services/meta.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
"use server";

import { Database } from "@/lib/supabase/types.gen";
import { SupabaseClient } from "@supabase/supabase-js";
import { DatabaseClient } from "@/lib/supabase/types";
import { unstable_cache } from "next/cache";

export const getSiteMeta = unstable_cache(
async (supabase: SupabaseClient<Database>) => {
async (supabase: DatabaseClient) => {
const { data } = await supabase.auth.admin.listUsers();
const { count: projects } = await supabase
.from("projects")
.select("*", { count: "estimated" });
.select("*", { count: "exact" });

return {
users: data.users.length,
Expand Down
4 changes: 2 additions & 2 deletions src/services/project/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SupabaseClient } from "@supabase/supabase-js";
import { DatabaseClient } from "@/lib/supabase/types";

export const getProject = async (projectId: string, client: SupabaseClient) => {
export const getProject = async (projectId: string, client: DatabaseClient) => {
const { data: project } = await client
.from("projects")
.select("*")
Expand Down
5 changes: 2 additions & 3 deletions src/services/tasks/api.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"use server";

import { GetTasksParams } from "@/components/TasksList/Tasks";
import { createClient } from "@/lib/supabase/client";
import { Task, TaskInsert, TaskUpdate } from "@/lib/supabase/types";
import { Database, Enums } from "@/lib/supabase/types.gen";
import { createClient } from "@/lib/supabase/server";
import { TaskInsert, TaskUpdate } from "@/lib/supabase/types";
import { revalidateTag, unstable_cache } from "next/cache";

export const getOwnTasks = async (filters: {
Expand Down

0 comments on commit 97489ae

Please sign in to comment.