-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase.js
More file actions
57 lines (47 loc) · 1.69 KB
/
Copy pathsupabase.js
File metadata and controls
57 lines (47 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* Supabase client — configure these two constants before deploying */
const SUPABASE_URL = 'https://glrecozajprxtxtfiped.supabase.co';
const SUPABASE_ANON_KEY = 'sb_publishable_MrasY7nJvnsGC1WKvVlTZg_CW3qfHxj';
const _client = window.supabase.createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
async function signUp(email, password, displayName) {
const { data, error } = await _client.auth.signUp({
email, password,
options: { data: { display_name: displayName } },
});
return { user: data?.user, error };
}
async function signInWithPassword(email, password) {
const { data, error } = await _client.auth.signInWithPassword({ email, password });
return { user: data?.user, error };
}
async function resetPassword(email) {
const { error } = await _client.auth.resetPasswordForEmail(email, {
redirectTo: 'https://raydl18.github.io/refclock',
});
return error;
}
async function signOut() {
const { error } = await _client.auth.signOut();
return error;
}
async function getUser() {
const { data: { user }, error } = await _client.auth.getUser();
return error ? null : user;
}
async function saveGame(gameRecord) {
const { error } = await _client.from('games').insert(gameRecord);
return error;
}
async function fetchGames() {
const { data, error } = await _client
.from('games')
.select('*')
.order('created_at', { ascending: false })
.limit(50);
return { data: data || [], error };
}
function onAuthStateChange(callback) {
_client.auth.onAuthStateChange((_event, session) => {
callback(session ? session.user : null);
});
}
window.SupabaseAPI = { signUp, signInWithPassword, resetPassword, signOut, getUser, saveGame, fetchGames, onAuthStateChange };