Global States (SPA)
Set state that is visible to all components
Introduction
Problem & Solution
import { createClient } from '@supabase/supabase-js'
import type { User } from '@supabase/supabase-js'
import { State } from '@weblabsjs/core'
// Create a single supabase client for interacting with your database
export const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key')
export const user = State<User | undefined>(undefined) //this is the splash view
import { div, p } from "@weblabsjs/core/components";
import { user as GlobalUser, supabase } from "../supabase";
import { AppNavigator, onLoad } from "@weblabsjs/core";
export default function SplashView() {
//in this view, we are responsible for loading
//the user and setting it in the global user object
onLoad(async () => {
const { data: { user } } = await supabase.auth.getUser()
if ( user != undefined ) {
GlobalUser.set(user)
AppNavigator("/feed")
} else {
AppNavigator("/login")
}
})
return div(
//your splash screen goes here
)
}Last updated