fix(frontend): don't show login button if user is logged in, redirect to profile on login

This commit is contained in:
Sam 2023-03-25 17:07:11 +01:00
parent 2cb735a0db
commit 8da83b3f8d
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
5 changed files with 11 additions and 5 deletions

View file

@ -1,6 +1,7 @@
<script lang="ts"> <script lang="ts">
import { PUBLIC_BASE_URL } from "$env/static/public"; import { PUBLIC_BASE_URL } from "$env/static/public";
import { Button } from "sveltestrap"; import { Button } from "sveltestrap";
import { userStore } from "$lib/store";
</script> </script>
<svelte:head> <svelte:head>
@ -16,7 +17,11 @@
<p class="fs-3">Create and share <em>all</em> your pronouns</p> <p class="fs-3">Create and share <em>all</em> your pronouns</p>
<p> <p>
{#if $userStore}
<Button href="/@{$userStore.name}" color="secondary" size="lg">Go to your profile</Button>
{:else}
<Button href="/auth/login" color="success" size="lg">Log in or sign up</Button> <Button href="/auth/login" color="success" size="lg">Log in or sign up</Button>
{/if}
</p> </p>
</div> </div>

View file

@ -35,7 +35,8 @@
localStorage.setItem("pronouns-token", token); localStorage.setItem("pronouns-token", token);
localStorage.setItem("pronouns-user", JSON.stringify(user)); localStorage.setItem("pronouns-user", JSON.stringify(user));
userStore.set(user); userStore.set(user);
goto("/"); addToast({ header: "Logged in", body: "Successfully logged in!" });
goto(`/@${user.name}`);
} }
}); });

View file

@ -25,7 +25,7 @@
localStorage.setItem("pronouns-user", JSON.stringify(resp.user)); localStorage.setItem("pronouns-user", JSON.stringify(resp.user));
userStore.set(resp.user); userStore.set(resp.user);
addToast({ header: "Welcome!", body: "Signed up successfully!" }); addToast({ header: "Welcome!", body: "Signed up successfully!" });
goto("/"); goto(`/@${resp.user.name}`);
} catch (e) { } catch (e) {
data.error = e as APIError; data.error = e as APIError;
} }

View file

@ -26,7 +26,7 @@
localStorage.setItem("pronouns-user", JSON.stringify(resp.user)); localStorage.setItem("pronouns-user", JSON.stringify(resp.user));
userStore.set(resp.user); userStore.set(resp.user);
addToast({ header: "Welcome!", body: "Signed up successfully!" }); addToast({ header: "Welcome!", body: "Signed up successfully!" });
goto("/"); goto(`/@${resp.user.name}`);
} catch (e) { } catch (e) {
data.error = e as APIError; data.error = e as APIError;
} }

View file

@ -26,7 +26,7 @@
localStorage.setItem("pronouns-user", JSON.stringify(resp.user)); localStorage.setItem("pronouns-user", JSON.stringify(resp.user));
userStore.set(resp.user); userStore.set(resp.user);
addToast({ header: "Welcome!", body: "Signed up successfully!" }); addToast({ header: "Welcome!", body: "Signed up successfully!" });
goto("/"); goto(`/@${resp.user.name}`);
} catch (e) { } catch (e) {
data.error = e as APIError; data.error = e as APIError;
} }