Skip to content

Instantly share code, notes, and snippets.

@rogie
Created February 14, 2023 15:13
Show Gist options
  • Select an option

  • Save rogie/1350193f3f467bb99163ebe98f6f59fb to your computer and use it in GitHub Desktop.

Select an option

Save rogie/1350193f3f467bb99163ebe98f6f59fb to your computer and use it in GitHub Desktop.
// creating the client
// https://supabase.com/docs/reference/javascript/initializing
import { createClient } from '@supabase/supabase-js';
import clientStorage from './FigmaClientStorage';
const supabase = createClient(
<URL>,
<PUBLIC_ANON_KEY>,
{
auth: {
storage: clientStorage
}
}
)
/* FigmaClientStorage
You'll notice references to FigmaScene.setClientStorage — this is not a native function, but rather, a set of async
utilities that I use to do all of my postMessage/onmessage handlers from the client end vs. the scene. You'll need
to replace that with your own version of postMessage, etc
*/
const store = {} //temporary storage
export default {
async setItem(key, value) {
store[key] = value
return await FigmaScene.setClientStorage(key, value)
},
async getItem(key) {
let value = store[key]
if (!value) {
let value = await FigmaScene.getClientStorage(key);
store[key] = value
}
return value
},
async removeItem(key) {
delete store[key]
return await FigmaScene.deleteClientStorage(key)
}
}
// Signup
const { user, error } = await supabase.auth.signUp({
email: email,
password: password,
options: {
data: {
avatar_url: figmaUser.photoUrl,
full_name: figmaUser.name,
figma_user_id: figmaUser.id
}
}
})
// Signout
const { error } = await supabase.auth.signOut()
// Signin (with password)
const { data, error } = await supabase.auth.signInWithPassword({
email: email,
password: password,
})
// Database call (joins profiles), ordering by id (newest first)
const { data, error } = await supabase
.from('textures')
.select(`
*,
profiles(
*
)
`)
.order('id', { ascending: false })
// Publishing to a table
const publishData = {
name: name,
description: description,
tags: tags.split(','),
data: texture,
user_id: session.user.id
}
const { data, error } = await supabase
.from('textures')
.upsert(publishData)
.select()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment