Deck ratings (comment + popup), remove Published badge from My decks
This commit is contained in:
+26
-3
@@ -1,5 +1,6 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import { supabase } from '../supabase.js';
|
||||
import { getEmailForUsername, updateProfile } from '../api/profile.js';
|
||||
|
||||
function createAuthStore() {
|
||||
const { subscribe, set, update } = writable({
|
||||
@@ -35,8 +36,21 @@ function createAuthStore() {
|
||||
setSession(current);
|
||||
});
|
||||
},
|
||||
login: async (email, password) => {
|
||||
login: async (emailOrUsername, password) => {
|
||||
update((s) => ({ ...s, error: null }));
|
||||
let email = (emailOrUsername ?? '').trim();
|
||||
if (!email) {
|
||||
update((s) => ({ ...s, error: 'Enter your email or username.' }));
|
||||
return false;
|
||||
}
|
||||
if (!email.includes('@')) {
|
||||
const resolved = await getEmailForUsername(email);
|
||||
if (!resolved) {
|
||||
update((s) => ({ ...s, error: 'No account with that username.' }));
|
||||
return false;
|
||||
}
|
||||
email = resolved;
|
||||
}
|
||||
try {
|
||||
const { error } = await supabase.auth.signInWithPassword({ email, password });
|
||||
if (error) {
|
||||
@@ -50,15 +64,24 @@ function createAuthStore() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
register: async (email, password) => {
|
||||
register: async (email, password, displayName) => {
|
||||
update((s) => ({ ...s, error: null }));
|
||||
try {
|
||||
const { data, error } = await supabase.auth.signUp({ email, password });
|
||||
const { data, error } = await supabase.auth.signUp({
|
||||
email,
|
||||
password,
|
||||
options: { data: { display_name: (displayName || '').trim() || null } },
|
||||
});
|
||||
if (error) {
|
||||
update((s) => ({ ...s, error: error.message }));
|
||||
return { success: false };
|
||||
}
|
||||
update((s) => ({ ...s, error: null }));
|
||||
if (data?.user?.id && data?.session && (displayName || '').trim()) {
|
||||
try {
|
||||
await updateProfile(data.user.id, { display_name: (displayName || '').trim() });
|
||||
} catch (_) {}
|
||||
}
|
||||
const needsConfirmation = data?.user && !data?.session;
|
||||
return { success: true, needsConfirmation, data };
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user