Skip to content

Commit 1ab64fb

Browse files
committed
add service client, update docs
1 parent fef0536 commit 1ab64fb

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
SUPABASE_AUTH_DISCORD_CLIENT_ID="1234567890"
22
SUPABASE_AUTH_DISCORD_SECRET="some_random_key"
33
NEXT_PUBLIC_SUPABASE_ANON_KEY="some_random_key, found by running supabase start or supabase status"
4+
SUPABASE_SERVICE_KEY="some_random_key, found by running supabase start or supabase status"
45
JWT_SECRET="super-secret-jwt-token-with-at-least-32-characters-long"

SETUP.md

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Copy the following output values to your environment file:
7777
`anon key` to `NEXT_PUBLIC_SUPABASE_ANON_KEY`
7878
`API URL` to `NEXT_PUBLIC_SUPABASE_URL`
7979
`JWT secret` to `JWT_SECRET`
80+
`service_role key` to `SUPABASE_SERVICE_KEY`
8081

8182
To stop running supabase, type `supabase stop` into your terminal.
8283

app/auth/callback/route.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createClient } from "@/lib/database/server";
2-
import { createServerClient } from "@supabase/ssr";
2+
import { createServiceClient } from "@/lib/database/service";
33
import { NextResponse } from "next/server";
44

55
interface DiscordGuildMemberResponse {
@@ -58,6 +58,9 @@ export async function GET(request: Request) {
5858
).then((res) => res.json());
5959

6060
if (!servers || servers?.code) {
61+
const serviceClient = createServiceClient();
62+
63+
await serviceClient.auth.admin.deleteUser(user.id);
6164
await supabase.auth.signOut();
6265
return NextResponse.redirect(`${origin}/403`);
6366
}

lib/database/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createServerClient, type CookieOptions } from "@supabase/ssr";
1+
import { createServerClient } from "@supabase/ssr";
22
import { cookies } from "next/headers";
33

44
export function createClient() {

lib/database/service.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { createClient } from "@supabase/supabase-js";
2+
3+
/**
4+
* SHOULD ONLY EVER BE USED ON SERVER
5+
*/
6+
export function createServiceClient() {
7+
return createClient(
8+
process.env.NEXT_PUBLIC_SUPABASE_URL!,
9+
process.env.SUPABASE_SERVICE_KEY!,
10+
{
11+
auth: {
12+
persistSession: false,
13+
autoRefreshToken: false,
14+
detectSessionInUrl: false,
15+
},
16+
}
17+
);
18+
}

0 commit comments

Comments
 (0)