Skip to content

Instantly share code, notes, and snippets.

@kangmingtay
Created August 7, 2023 15:33
Show Gist options
  • Save kangmingtay/c3559556033ba599f51182cf5956ac6c to your computer and use it in GitHub Desktop.
Save kangmingtay/c3559556033ba599f51182cf5956ac6c to your computer and use it in GitHub Desktop.
import { createClient } from "@supabase/supabase-js";
const supabaseUrl = "your-project-ref";
const supabaseKey = "your-anon-key";
// Attempt to reproduce https://github.com/supabase/supabase-js/issues/805
async function main() {
try {
const supabase = createClient(supabaseUrl, supabaseKey, {
auth: {
persistSession: false,
},
});
const { data, error } = await supabase.auth.signInWithPassword({
email: "foo@example.com",
password: "secret123",
});
if (error) throw error;
await supabase.auth.updateUser({
data: {
colour: "red",
},
});
const { data: newSession, error: refreshSessionError } =
await supabase.auth.refreshSession();
if (refreshSessionError) throw refreshSessionError;
console.log("First update: ", newSession.user.user_metadata);
await supabase.auth.updateUser({
data: {
colour: "blue",
},
});
const { data: newSession2, error: refreshSessionError2 } =
await supabase.auth.refreshSession();
if (refreshSessionError2) throw refreshSessionError2;
console.log("Second update: ", newSession2.user.user_metadata);
} catch (err) {
console.log("handling error");
console.log(err);
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment