Created
November 12, 2023 08:58
-
-
Save solace/0414f12616f3fb362787d35a7b499d31 to your computer and use it in GitHub Desktop.
NextJS middleware to fix "Invalid Refresh Token: Already Used" from supabase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Requested fix for https://github.com/supabase/gotrue/issues/1290 | |
export async function middleware(req: NextRequest) { | |
const res = NextResponse.next(); | |
const supabase = createMiddlewareClient({req, res}); | |
const {error} = await supabase.auth.getSession(); | |
// Trying to fix "Invalid Refresh Token: Already Used" | |
// https://github.com/vercel/next.js/issues/40146#issuecomment-1236392823 | |
if (error) { | |
const prefix = ( | |
process.env.NEXT_PUBLIC_SUPABASE_URL.split('//').pop() as string | |
) | |
.split('.') | |
.shift(); | |
deleteCookie(req, res, `sb-${prefix}-auth-token`); | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment