Closed Mupati closed 2 weeks ago
And for Deno(Supabase Edge Function) please. I try, but error Error: Failed to create room: Unauthorized
error Error: Failed to create room: Unauthorized
at Object.handler (file:///home/deno/functions/create-room/index.ts:83:13)
at eventLoopTick (ext:core/01_core.js:183:11)
at async handleHttp (ext:sb_core_main_js/js/http.js:93:17)
import {
create,
getNumericDate,
Header,
Payload,
} from "https://deno.land/x/djwt/mod.ts";
const access_key = Deno.env.get("APP_ACCESS_KEY");
const app_secret = Deno.env.get("APP_SECRET");
const payload: Payload = {
access_key: access_key,
type: "management",
version: 2,
iat: getNumericDate(Math.floor(Date.now() / 1000)),
nbf: getNumericDate(Math.floor(Date.now() / 1000)),
exp: getNumericDate(60 * 60 * 24), // 24 hours from now
};
const header: Header = {
alg: "HS256",
typ: "JWT",
};
const cryptoKey = await crypto.subtle.importKey(
"raw",
new TextEncoder().encode(app_secret),
{ name: "HMAC", hash: { name: "SHA-256" } },
false,
["sign"],
);
let token;
try {
if (!app_secret) {
throw new Error("Secret not found");
}
token = await create(header, payload, cryptoKey);
} catch (err) {
console.error(err);
}
And for Deno(Supabase Edge Function) please. I try, but error Error: Failed to create room: Unauthorized
error Error: Failed to create room: Unauthorized at Object.handler (file:///home/deno/functions/create-room/index.ts:83:13) at eventLoopTick (ext:core/01_core.js:183:11) at async handleHttp (ext:sb_core_main_js/js/http.js:93:17)
import { create, getNumericDate, Header, Payload, } from "https://deno.land/x/djwt/mod.ts"; const access_key = Deno.env.get("APP_ACCESS_KEY"); const app_secret = Deno.env.get("APP_SECRET"); const payload: Payload = { access_key: access_key, type: "management", version: 2, iat: getNumericDate(Math.floor(Date.now() / 1000)), nbf: getNumericDate(Math.floor(Date.now() / 1000)), exp: getNumericDate(60 * 60 * 24), // 24 hours from now }; const header: Header = { alg: "HS256", typ: "JWT", }; const cryptoKey = await crypto.subtle.importKey( "raw", new TextEncoder().encode(app_secret), { name: "HMAC", hash: { name: "SHA-256" } }, false, ["sign"], );
let token; try { if (!app_secret) { throw new Error("Secret not found"); } token = await create(header, payload, cryptoKey); } catch (err) { console.error(err); }
I'm not sure your comment belongs under this issue
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.
To help the Golang users, add sample code for token generation as we have for the other languages over here