auth-js
auth-js copied to clipboard
supabase.auth.api.setAuthCookie(req, res) not working in nextjs API route. Invalid JWT.
I am trying to fetch image from storage through nextjs API. I am using -
"next": "^12.1.6",
"@supabase/supabase-js": "1.35.2",
"react": "^18.1.0",
- If RLS is not set then I am able to fetch Image.
- If RLS is set I am not able to fetch image. With following error -
{"statusCode":"401","error":"Invalid JWT","message":"new row violates row-level security policy for table \"objects\""}
I have already set auth cookies by calling following code inside auth
route
import { NextApiRequest, NextApiResponse } from "next";
import { supabase } from "../../lib/supabaseClient";
export default function handler(req: NextApiRequest, res: NextApiResponse) {
supabase.auth.api.setAuthCookie(req, res);
}
Code for calling my auth
api is inside _app.tsx
supabase.auth.onAuthStateChange((event, session) => {
fetch("/api/auth", {
method: "POST",
headers: new Headers({ "Content-Type": "application/json" }),
credentials: "same-origin",
body: JSON.stringify({ event, session }),
})
});
Hey @roker15 — what are your RLS settings?
Hey all,
Transferring this to the Supabase Auth repo so we can best track this. @roker15 do let us know if you are still facing this issue -- happy to jump in and help.
Hey @roker15 this sounds like a problem with your RLS policies. Please open a support ticket if you need assistance.