fix login page showing when logged in

This commit is contained in:
ari melody 2024-06-29 15:52:52 +01:00
parent 8f41613179
commit ce1dfc388f
Signed by: ari
GPG key ID: CF99829C92678188
3 changed files with 53 additions and 45 deletions

View file

@ -15,6 +15,7 @@ export class Client {
constructor() { constructor() {
this.instance = null; this.instance = null;
this.app = null; this.app = null;
this.user = null;
this.cache = { this.cache = {
users: {}, users: {},
emojis: {}, emojis: {},
@ -86,10 +87,13 @@ export class Client {
async verifyCredentials() { async verifyCredentials() {
const data = await api.verifyCredentials(); const data = await api.verifyCredentials();
if (!data) return false; if (!data) {
this.user = false;
return false;
}
this.user = await api.parseUser(data); this.user = await api.parseUser(data);
client.set(this); client.set(this);
return data; return this.user;
} }
async getTimeline(last_post_id) { async getTimeline(last_post_id) {

2
src/routes/+page.js Normal file
View file

@ -0,0 +1,2 @@
export const prerender = true;
export const ssr = false;

View file

@ -10,8 +10,7 @@
import { get } from 'svelte/store'; import { get } from 'svelte/store';
let client = get(Client.get()); let client = get(Client.get());
let ready = !!client; let logged_in;
let logged_in = client.app && client.app.token;
let instance_url_error = false; let instance_url_error = false;
let logging_in = false; let logging_in = false;
@ -27,11 +26,16 @@
if (client.app && client.app.token) { if (client.app && client.app.token) {
// this triggers the client actually getting the authenticated user's data. // this triggers the client actually getting the authenticated user's data.
client.verifyCredentials().then(res => { client.verifyCredentials().then(user => {
if (res) { if (user) {
console.log(`Logged in as @${client.user.username}@${client.user.host}`); console.log(`Logged in as @${user.username}@${user.host}`);
logged_in = true;
} else {
logged_in = false;
} }
}); });
} else {
logged_in = false;
} }
function log_in(event) { function log_in(event) {
@ -67,19 +71,11 @@
</header> </header>
<main> <main>
{#if ready} {#if logged_in === undefined}
{#if logged_in} <div class="loading throb">
<header> <span>just a moment...</span>
<h1>Home</h1> </div>
<nav> {:else if logged_in === false}
<Button centered active>Home</Button>
<Button centered disabled>Local</Button>
<Button centered disabled>Federated</Button>
</nav>
</header>
<Feed />
{:else}
<form on:submit={log_in} id="login-form"> <form on:submit={log_in} id="login-form">
<img class="app-icon light-only" src={LogoLight} width="320px" aria-label="Space Social"/> <img class="app-icon light-only" src={LogoLight} width="320px" aria-label="Space Social"/>
<img class="app-icon dark-only" src={LogoDark} width="320px" aria-label="Space Social"/> <img class="app-icon dark-only" src={LogoDark} width="320px" aria-label="Space Social"/>
@ -103,11 +99,17 @@
<p class="form-footer">made with ❤️ by <a href="https://arimelody.me">ari melody</a>, 2024</p> <p class="form-footer">made with ❤️ by <a href="https://arimelody.me">ari melody</a>, 2024</p>
</form> </form>
{/if}
{:else} {:else}
<div class="loading throb"> <header>
<span>just a moment...</span> <h1>Home</h1>
</div> <nav>
<Button centered active>Home</Button>
<Button centered disabled>Local</Button>
<Button centered disabled>Federated</Button>
</nav>
</header>
<Feed />
{/if} {/if}
</main> </main>