prevent login page flash on initial render
This commit is contained in:
parent
d72a6dc8df
commit
252c50029f
|
@ -13,11 +13,10 @@
|
||||||
import { auth } from "stores/backend"
|
import { auth } from "stores/backend"
|
||||||
|
|
||||||
let modal
|
let modal
|
||||||
|
|
||||||
console.log($auth.user)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $auth.user}
|
{#if $auth}
|
||||||
|
{#if $auth.user}
|
||||||
<div class="root">
|
<div class="root">
|
||||||
<div class="ui-nav">
|
<div class="ui-nav">
|
||||||
<div class="home-logo">
|
<div class="home-logo">
|
||||||
|
@ -52,10 +51,11 @@
|
||||||
<slot />
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<section class="login">
|
<section class="login">
|
||||||
<LoginForm />
|
<LoginForm />
|
||||||
</section>
|
</section>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
@ -10,7 +10,7 @@ async function checkAuth() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createAuthStore() {
|
export function createAuthStore() {
|
||||||
const { subscribe, set } = writable({})
|
const { subscribe, set } = writable(null)
|
||||||
|
|
||||||
checkAuth()
|
checkAuth()
|
||||||
.then(user => set({ user }))
|
.then(user => set({ user }))
|
||||||
|
@ -21,16 +21,13 @@ export function createAuthStore() {
|
||||||
login: async creds => {
|
login: async creds => {
|
||||||
const response = await api.post(`/api/admin/auth`, creds)
|
const response = await api.post(`/api/admin/auth`, creds)
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
if (json.user) {
|
set({ user: json })
|
||||||
localStorage.setItem("auth:user", JSON.stringify(json.user))
|
|
||||||
set({ user: json.user })
|
|
||||||
}
|
|
||||||
return json
|
return json
|
||||||
},
|
},
|
||||||
logout: async () => {
|
logout: async () => {
|
||||||
const response = await api.post(`/api/auth/logout`)
|
const response = await api.post(`/api/auth/logout`)
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
set({ user: false })
|
set({ user: null })
|
||||||
},
|
},
|
||||||
createUser: async user => {
|
createUser: async user => {
|
||||||
const response = await api.post(`/api/admin/users`, user)
|
const response = await api.post(`/api/admin/users`, user)
|
||||||
|
|
Loading…
Reference in New Issue