-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch-utils.js
More file actions
58 lines (42 loc) · 1.62 KB
/
Copy pathfetch-utils.js
File metadata and controls
58 lines (42 loc) · 1.62 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
58
const SUPABASE_URL = 'https://hdstylaggwivnddufiyv.supabase.co';
const SUPABASE_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imhkc3R5bGFnZ3dpdm5kZHVmaXl2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2NTM2OTI4MzAsImV4cCI6MTk2OTI2ODgzMH0.pTPAAOVv6yWdNxYG38icrBAqxVNH8c1TFl9WPdEaT6c';
const client = supabase.createClient(SUPABASE_URL, SUPABASE_KEY);
export function getUser() {
return client.auth.session() && client.auth.session().user;
}
export function checkAuth() {
const user = getUser();
if (!user) location.replace('../');
}
export function redirectIfLoggedIn() {
if (getUser()) {
location.replace('./Character-select');
}
}
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();
return (window.location.href = '../');
}
export async function getCharacters() {
const response = await client.from('characters').select('*');
return checkError(response);
}
function checkError({ data, error }) {
return error ? console.error(error) : data;
}
export async function getChar(id) {
const response = await client.from('characters').select('*').match({ id: id }).single();
return checkError(response);
}
export async function getStory(id) {
const response = await client.from('dyn_pages').select('*').match({ id: id }).single();
return checkError(response);
}