aboutsummaryrefslogtreecommitdiffstats
path: root/ui/src/state
diff options
context:
space:
mode:
Diffstat (limited to 'ui/src/state')
-rw-r--r--ui/src/state/client.ts16
-rw-r--r--ui/src/state/models.ts16
-rw-r--r--ui/src/state/store.ts3
3 files changed, 29 insertions, 6 deletions
diff --git a/ui/src/state/client.ts b/ui/src/state/client.ts
index f43683c1..5ec0d8a7 100644
--- a/ui/src/state/client.ts
+++ b/ui/src/state/client.ts
@@ -11,3 +11,19 @@ export async function sessionToken(): Promise<String> {
export async function settings(): Promise<Settings> {
return await invoke("config");
}
+
+export async function login(
+ username: string,
+ password: string,
+ key: string,
+): Promise<string> {
+ return await invoke("login", { username, password, key });
+}
+
+export async function register(
+ username: string,
+ email: string,
+ password: string,
+): Promise<string> {
+ return await invoke("register", { username, email, password });
+}
diff --git a/ui/src/state/models.ts b/ui/src/state/models.ts
index 57db44ae..c1d97f4b 100644
--- a/ui/src/state/models.ts
+++ b/ui/src/state/models.ts
@@ -1,12 +1,18 @@
import Database from "@tauri-apps/plugin-sql";
-export interface User {
- username: string;
+export class User {
+ username: string | null;
+
+ constructor(username: string) {
+ this.username = username;
+ }
+
+ isLoggedIn(): boolean {
+ return this.username !== "" && this.username !== null;
+ }
}
-export const DefaultUser: User = {
- username: "",
-};
+export const DefaultUser: User = new User("");
export interface HomeInfo {
historyCount: number;
diff --git a/ui/src/state/store.ts b/ui/src/state/store.ts
index 5e2570bb..6746c1fb 100644
--- a/ui/src/state/store.ts
+++ b/ui/src/state/store.ts
@@ -94,6 +94,7 @@ export const useStore = create<AtuinState>()((set, get) => ({
session = await sessionToken();
} catch (e) {
console.log("Not logged in, so not refreshing user");
+ set({ user: DefaultUser });
return;
}
let url = config.sync_address + "/api/v0/me";
@@ -105,7 +106,7 @@ export const useStore = create<AtuinState>()((set, get) => ({
});
let me = await res.json();
- set({ user: me });
+ set({ user: new User(me.username) });
},
historyNextPage: (query?: string) => {