mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
feat: create fetchUser method & add to login page
This commit is contained in:
+18
-1
@@ -1,4 +1,21 @@
|
||||
import type { Models } from 'src/sdk';
|
||||
import { writable } from 'svelte/store';
|
||||
import { sdkForConsole } from './sdk';
|
||||
|
||||
export const user = writable<Models.User<Record<string, unknown>>>();
|
||||
function createUserStore() {
|
||||
const { subscribe, set } = writable<Models.User<Record<string, unknown>>>();
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
set,
|
||||
fetchUser: async () => {
|
||||
try {
|
||||
set(await sdkForConsole.account.get());
|
||||
} catch (error) {
|
||||
//TODO: take care what happens here
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const user = createUserStore();
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { page } from '$app/stores';
|
||||
import { sdkForConsole } from '$lib/stores/sdk';
|
||||
import { user } from '$lib/stores/user';
|
||||
import { onMount } from 'svelte';
|
||||
import Notifications from '$lib/layout/notifications.svelte';
|
||||
@@ -16,7 +15,7 @@
|
||||
onMount(async () => {
|
||||
try {
|
||||
if (!$user) {
|
||||
user.set(await sdkForConsole.account.get());
|
||||
user.fetchUser();
|
||||
}
|
||||
|
||||
if (!$page.url.pathname.startsWith('/console')) {
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
import { Button, Form, FormItem, InputEmail, InputPassword } from '$lib/elements/forms';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { sdkForConsole } from '$lib/stores/sdk';
|
||||
import { user } from '$lib/stores/user';
|
||||
|
||||
let mail: string, pass: string;
|
||||
|
||||
const login = async () => {
|
||||
try {
|
||||
await sdkForConsole.account.createSession(mail, pass);
|
||||
user.fetchUser();
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: 'Successfully logged in.'
|
||||
|
||||
Reference in New Issue
Block a user