forked from blisstown/campfire
fixed login flow inconsistency
This commit is contained in:
parent
998e8f2517
commit
abab0df83f
10 changed files with 65 additions and 45 deletions
|
@ -1,8 +1,9 @@
|
|||
import { client } from '../client/client.js';
|
||||
import { client } from '$lib/client/client.js';
|
||||
import { user } from '$lib/stores/user.js';
|
||||
import { capabilities } from '../client/instance.js';
|
||||
import Post from '../post.js';
|
||||
import User from '../user/user.js';
|
||||
import Emoji from '../emoji.js';
|
||||
import Post from '$lib/post.js';
|
||||
import User from '$lib/user/user.js';
|
||||
import Emoji from '$lib/emoji.js';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
export async function createApp(host) {
|
||||
|
@ -92,7 +93,7 @@ export async function verifyCredentials() {
|
|||
}
|
||||
|
||||
export async function getNotifications(since_id, limit, types) {
|
||||
if (!get(client).user) return false;
|
||||
if (!get(user)) return false;
|
||||
|
||||
let url = `https://${get(client).instance.host}/api/v1/notifications`;
|
||||
|
||||
|
@ -112,6 +113,7 @@ export async function getNotifications(since_id, limit, types) {
|
|||
}
|
||||
|
||||
export async function getTimeline(last_post_id) {
|
||||
if (!get(user)) return false;
|
||||
let url = `https://${get(client).instance.host}/api/v1/timelines/home`;
|
||||
if (last_post_id) url += "?max_id=" + last_post_id;
|
||||
const data = await fetch(url, {
|
||||
|
|
|
@ -2,7 +2,7 @@ import { Instance, server_types } from './instance.js';
|
|||
import * as api from './api.js';
|
||||
import { get, writable } from 'svelte/store';
|
||||
import { last_read_notif_id } from '$lib/notifications.js';
|
||||
import { user } from '$lib/stores/user.js';
|
||||
import { user, logged_in } from '$lib/stores/user.js';
|
||||
|
||||
export const client = writable(false);
|
||||
|
||||
|
@ -206,6 +206,7 @@ export class Client {
|
|||
console.warn("Failed to log out correctly; ditching the old tokens anyways.");
|
||||
}
|
||||
localStorage.removeItem(save_name);
|
||||
logged_in.set(false);
|
||||
client.set(new Client());
|
||||
console.log("Logged out successfully.");
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ export async function getNotifications() {
|
|||
}
|
||||
}
|
||||
}
|
||||
notif.status = await api.parsePost(notif.status, 0, false);
|
||||
notif.status = notif.status ? await api.parsePost(notif.status, 0, false) : null;
|
||||
notifications.update(notifications => [...notifications, notif]);
|
||||
}
|
||||
last_read_notif_id.set(data[0].id);
|
||||
|
|
|
@ -1,4 +1,22 @@
|
|||
import { writable } from 'svelte/store';
|
||||
import { client } from '$lib/client/client.js';
|
||||
import * as api from '$lib/client/api.js';
|
||||
import { get, writable } from 'svelte/store';
|
||||
|
||||
export let user = writable(0);
|
||||
export let logged_in = writable(false);
|
||||
|
||||
export async function getUser() {
|
||||
// already known
|
||||
if (get(user)) return get(user);
|
||||
|
||||
// cannot provide- not logged in
|
||||
if (!get(client).app || !get(client).app.token) return false;
|
||||
|
||||
// logged in- attempt to retrieve using token
|
||||
const data = await api.verifyCredentials();
|
||||
if (!data) return false;
|
||||
|
||||
user.set(await api.parseUser(data));
|
||||
console.log(`Logged in as @${get(user).username}@${get(user).host}`);
|
||||
return get(user);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import Button from './Button.svelte';
|
||||
import Feed from './Feed.svelte';
|
||||
import { client } from '$lib/client/client.js';
|
||||
import { user } from '$lib/stores/user.js';
|
||||
import { play_sound } from '$lib/sound.js';
|
||||
import { getTimeline } from '$lib/timeline.js';
|
||||
import { getNotifications } from '$lib/notifications.js';
|
||||
|
@ -150,11 +151,11 @@
|
|||
</div>
|
||||
|
||||
<div id="account-button">
|
||||
<img src={$client.user.avatar_url} class="account-avatar" height="64px" alt="" aria-hidden="true" on:click={() => play_sound()}>
|
||||
<img src={$user.avatar_url} class="account-avatar" height="64px" alt="" aria-hidden="true" on:click={() => play_sound()}>
|
||||
<div class="account-name" aria-hidden="true">
|
||||
<a href={$client.user.url} class="nickname" title={$client.user.nickname}>{$client.user.nickname}</a>
|
||||
<span class="username" title={`@${$client.user.username}@${$client.user.host}`}>
|
||||
{`@${$client.user.username}@${$client.user.host}`}
|
||||
<a href={$user.url} class="nickname" title={$user.nickname}>{$user.nickname}</a>
|
||||
<span class="username" title={`@${$user.username}@${$user.host}`}>
|
||||
{`@${$user.username}@${$user.host}`}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
}
|
||||
</script>
|
||||
|
||||
<a class="notification" href={`/post/${data.status.id}`} aria-label={aria_label}>
|
||||
<a class="notification" href={data.status ? `/post/${data.status.id}` : null} aria-label={aria_label}>
|
||||
<header aria-hidden>
|
||||
<span class="notif-icon">
|
||||
{#if data.type === "favourite"}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue