[英]Firebase auth works, but Ui is blinking username to undefined in svelte
<div>
<div>
{$fbUser?.email}
</div>
{#if !$fbUser}
<a href="/auth">go auth</a>
{/if}
</div>
export const actions: Actions = {
register: async ({ request }) => {
const data = await request.formData();
const email = String(data.get('email'));
const password = String(data.get('password'));
try {
await fbUser.createUser({ email, password });
} catch (e) {
if (e instanceof FirebaseError) {
return fail(409, {
failed: true,
error: e.message
});
}
}
throw redirect(307, "/home")
},
const userWritable = writable<User | null>(fb_auth.currentUser);
function authStore() {
const { set, subscribe, update } = userWritable;
const changes = () => onAuthStateChanged(fb_auth, (u) => {
if (u) set(u)
else update((curr) => curr = u)
})
return {
subscribe,
createUser: async (user: Register) => {
await createUserWithEmailAndPassword(fb_auth, user.email, user.password);
changes()
},
I tried installing onAuthStateChanged in +page.svelte instead of store using load function for onAuthStateChanged... but all result are same.我尝试在 +page.svelte 中安装 onAuthStateChanged 而不是使用 load function for onAuthStateChanged 安装 onAuthStateChanged ... 但所有结果都是相同的。 email shows very shortly after that it is changed to undefined.
email 不久后显示为未定义。 seems serverside(firebase) works, but i think im missing something on ui concepts
似乎服务器端(firebase)有效,但我认为我在 ui 概念上遗漏了一些东西
Try to add an await block surround your div in +page.svelte尝试在 +page.svelte 中的 div 周围添加一个等待块
{#await fbUser}
<div>
<div>
{$fbUser?.email}
</div>
{#if !$fbUser}
<a href="/auth">go auth</a>
{/if}
</div>
{/await}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.