@@ -3,12 +3,12 @@ import { createDbStore, supabaseAdapter, DbRow, DbStoreError } from "../src/inde
33import { AuthResponse , createClient , Session , SupabaseClient } from "@supabase/supabase-js" ;
44import { reconcile } from "solid-js/store" ;
55
6- const TodoList = ( props : { client : SupabaseClient , logout : ( ) => void } ) => {
6+ const TodoList = ( props : { client : SupabaseClient ; logout : ( ) => void } ) => {
77 const [ error , setError ] = createSignal < DbStoreError < DbRow > > ( ) ;
88 ( globalThis as any ) . supabaseClient = props . client ;
99 const [ todos , setTodos ] = createDbStore ( {
1010 adapter : supabaseAdapter ( { client : props . client , table : "todos" } ) ,
11- defaultFields : [ 'id' , ' user_id' ] ,
11+ defaultFields : [ "id" , " user_id" ] ,
1212 onError : setError ,
1313 } ) ;
1414 const [ edit , setEdit ] = createSignal < DbRow > ( ) ;
@@ -79,39 +79,37 @@ const TodoList = (props: { client: SupabaseClient, logout: () => void }) => {
7979
8080const App : Component = ( ) => {
8181 // these are public keys that will end up in the client in any case:
82- const client =
83- createClient (
84- import . meta. env . VITE_SUPABASE_URL ,
85- import . meta. env . VITE_SUPABASE_KEY
86- ) ;
82+ const client = createClient ( import . meta. env . VITE_SUPABASE_URL , import . meta. env . VITE_SUPABASE_KEY ) ;
8783 const [ session , setSession ] = createSignal < Session > ( ) ;
88- const [ error , setError ] = createSignal ( '' ) ;
84+ const [ error , setError ] = createSignal ( "" ) ;
8985 const handleAuthPromise = ( { error, data } : AuthResponse ) => {
9086 if ( error ) {
91- setError ( error . toString ( ) )
87+ setError ( error . toString ( ) ) ;
9288 } else {
9389 setSession ( data . session ?? undefined ) ;
9490 }
9591 } ;
9692 onMount ( ( ) => client . auth . refreshSession ( ) . then ( handleAuthPromise ) ) ;
9793 const login = ( ) => {
9894 const email = ( document . querySelector ( '[type="email"]' ) as HTMLInputElement | null ) ?. value ;
99- const password = ( document . querySelector ( '[type="password"]' ) as HTMLInputElement | null ) ?. value ;
95+ const password = ( document . querySelector ( '[type="password"]' ) as HTMLInputElement | null )
96+ ?. value ;
10097 if ( ! email || ! password ) {
101- setError ( ' please provide an email and password' ) ;
98+ setError ( " please provide an email and password" ) ;
10299 return ;
103100 }
104101 client . auth . signInWithPassword ( { email, password } ) . then ( handleAuthPromise ) ;
105102 } ;
106103 const register = ( ) => {
107104 const email = ( document . querySelector ( '[type="email"]' ) as HTMLInputElement | null ) ?. value ;
108- const password = ( document . querySelector ( '[type="password"]' ) as HTMLInputElement | null ) ?. value ;
105+ const password = ( document . querySelector ( '[type="password"]' ) as HTMLInputElement | null )
106+ ?. value ;
109107 if ( ! email || ! password ) {
110- setError ( ' please provide an email and password' ) ;
108+ setError ( " please provide an email and password" ) ;
111109 return ;
112110 }
113111 client . auth . signUp ( { email, password } ) . then ( handleAuthPromise ) ;
114- }
112+ } ;
115113
116114 return (
117115 < div class = "box-border flex min-h-screen w-full flex-col items-center justify-center space-y-4 bg-gray-800 p-24 text-white" >
@@ -121,25 +119,34 @@ const App: Component = () => {
121119 when = { session ( ) }
122120 fallback = {
123121 < >
124- < Show when = { error ( ) } > < p > { error ( ) } </ p > </ Show >
122+ < Show when = { error ( ) } >
123+ < p > { error ( ) } </ p >
124+ </ Show >
125125 < p >
126126 < label >
127- Email < input type = "email" onInput = { ( ) => setError ( '' ) } />
127+ Email < input type = "email" onInput = { ( ) => setError ( "" ) } />
128128 </ label >
129129 </ p >
130130 < p >
131131 < label >
132132 Password < input type = "password" />
133133 </ label >
134134 </ p >
135- < button class = "btn" onClick = { login } > sign in</ button >
136- < button class = "btn" onClick = { register } > sign up</ button >
135+ < button class = "btn" onClick = { login } >
136+ sign in
137+ </ button >
138+ < button class = "btn" onClick = { register } >
139+ sign up
140+ </ button >
137141 </ >
138142 }
139143 >
140144 < TodoList
141145 client = { client }
142- logout = { ( ) => { setSession ( undefined ) ; client . auth . signOut ( ) ; } }
146+ logout = { ( ) => {
147+ setSession ( undefined ) ;
148+ client . auth . signOut ( ) ;
149+ } }
143150 />
144151 </ Show >
145152 </ div >
0 commit comments