This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
generated from alchemycodelab/web-01-todo-supabase
/
fetch-utils.js
72 lines (52 loc) · 1.96 KB
/
fetch-utils.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const SUPABASE_URL = 'https://gxwgjhfyrlwiqakdeamc.supabase.co';
const SUPABASE_KEY =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYzNjQxMTMxMiwiZXhwIjoxOTUxOTg3MzEyfQ.PHekiwfLxT73qQsLklp0QFEfNx9NlmkssJFDnlvNIcA';
const client = supabase.createClient(SUPABASE_URL, SUPABASE_KEY);
export async function createTodo(todo) {
// create a single incomplete todo with the correct 'todo' property for this user in supabase
// once you have a response from supabase, comment this back in:
// return checkError(response);
}
export async function deleteAllTodos() {
// delete all todos for this user in supabase
// once you have a response from supabase, comment this back in:
// return checkError(response);
}
export async function getTodos() {
// get all todos for this user from supabase
// once you have a response from supabase, comment this back in:
// return checkError(response);
}
export async function completeTodo(id) {
// find the and update (set complete to true), the todo that matches the correct id
// once you have a response from supabase, comment this back in:
// return checkError(response);
}
export function getUser() {
return client.auth.session() && client.auth.session().user;
}
export function checkAuth() {
const user = getUser();
if (!user) location.replace('../');
}
export function redirectIfLoggedIn() {
const user = getUser();
if (user) {
location.replace('./todos');
}
}
export async function signupUser(email, password) {
const response = await client.auth.signUp({ email, password });
return response.user;
}
export async function signInUser(email, password) {
const response = await client.auth.signIn({ email, password });
return response.user;
}
export async function logout() {
await client.auth.signOut();
window.location.replace('../');
}
function checkError({ data, error }) {
return error ? console.error(error) : data;
}