Realtime not working with Custom Jwt with RLS
If i enable my RLS, i am able to do normal fetching from a custom JWT, which means RLS is working. But, real-time subscription is not working, and i am not able to fetch anything from the table. This issue is kinda similar to - https://stackoverflow.com/questions/79583118/supabase-realtime-subscription-not-working-with-custom-jwt-and-rls-in-next-js
i even tried implementing what's there on StackOverflow comment, but still not working. Code for reference:
const now = Math.floor(Date.now() / 1000); // current time in seconds
async function createJwt(payload) {
const header = {
alg: "HS256",
typ: "JWT"
};
const encodedHeader = base64UrlEncode(JSON.stringify(header));
const encodedPayload = base64UrlEncode(JSON.stringify(payload));
const data =
// SIGN WITH JWT SECRET
const key = await crypto.subtle.importKey("raw", new TextEncoder().encode(JWT_SECRET), {
name: "HMAC",
hash: "SHA-256"
}, false, [
"sign"
]);
const signature = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(data));
const encodedSig = base64UrlEncode(new Uint8Array(signature));
return
}
const exp = now + 30 * 24 * 60 * 60; // 30 days in seconds
const token = await createJwt({
sub: unique_id,
unique_id: unique_id,
role: "authenticated",
exp
});
i even tried implementing what's there on StackOverflow comment, but still not working. Code for reference:
const now = Math.floor(Date.now() / 1000); // current time in seconds
async function createJwt(payload) {
const header = {
alg: "HS256",
typ: "JWT"
};
const encodedHeader = base64UrlEncode(JSON.stringify(header));
const encodedPayload = base64UrlEncode(JSON.stringify(payload));
const data =
${encodedHeader}.${encodedPayload};// SIGN WITH JWT SECRET
const key = await crypto.subtle.importKey("raw", new TextEncoder().encode(JWT_SECRET), {
name: "HMAC",
hash: "SHA-256"
}, false, [
"sign"
]);
const signature = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(data));
const encodedSig = base64UrlEncode(new Uint8Array(signature));
return
${data}.${encodedSig};}
const exp = now + 30 * 24 * 60 * 60; // 30 days in seconds
const token = await createJwt({
sub: unique_id,
unique_id: unique_id,
role: "authenticated",
exp
});