Skip to content

Commit

Permalink
Updating supabase middleware away from deprecated createServerClient …
Browse files Browse the repository at this point in the history
…method
  • Loading branch information
k-thornton committed Aug 23, 2024
1 parent 25a1950 commit 55c654f
Showing 1 changed file with 14 additions and 35 deletions.
49 changes: 14 additions & 35 deletions utils/supabase/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createServerClient, type CookieOptions } from '@supabase/ssr';
import { createServerClient, type CookieMethodsServer } from '@supabase/ssr';
import { type NextRequest, NextResponse } from 'next/server';

export const createClient = (request: NextRequest) => {
Expand All @@ -14,46 +14,25 @@ export const createClient = (request: NextRequest) => {
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
get(name: string) {
return request.cookies.get(name)?.value;
getAll() {
return request.cookies.getAll()
},
set(name: string, value: string, options: CookieOptions) {
// If the cookie is updated, update the cookies for the request and response
request.cookies.set({
name,
value,
...options
});
setAll(cookiesToSet) {
cookiesToSet.forEach(({ name, value, options }) => request.cookies.set(name, value))
response = NextResponse.next({
request: {
headers: request.headers
}
});
response.cookies.set({
name,
value,
...options
});
})
cookiesToSet.forEach(({ name, value, options }) =>
response.cookies.set({
name,
value,
...options
})
)
},
remove(name: string, options: CookieOptions) {
// If the cookie is removed, update the cookies for the request and response
request.cookies.set({
name,
value: '',
...options
});
response = NextResponse.next({
request: {
headers: request.headers
}
});
response.cookies.set({
name,
value: '',
...options
});
}
}
} as CookieMethodsServer
}
);

Expand Down

0 comments on commit 55c654f

Please sign in to comment.