Skip to content

Commit

Permalink
Releases v1.0.1: Update navigation method in auth.js and Navbar.svelte
Browse files Browse the repository at this point in the history
  • Loading branch information
XPH0816 committed Jun 19, 2024
1 parent 5bf305e commit 4d07185
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "libraryroombookingsystem",
"private": true,
"version": "1.0.0",
"version": "1.0.1",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "LibraryRoomBookingSystem"
version = "1.0.0"
version = "1.0.1"
description = "A Library Room Booking System built with Tauri and Rust"
authors = ["Lim Shi Song limshisong123@gmail.com"]
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"package": {
"productName": "library-room-booking-system",
"version": "1.0.0"
"version": "1.0.1"
},
"tauri": {
"allowlist": {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { invoke } from "@tauri-apps/api/tauri";
import { goto } from "$app/navigation";
import { hashPassword, verify } from "./crypto/hashing";
import Cookies from "js-cookie";
import { getDB } from "./db";
Expand All @@ -19,7 +20,7 @@ export async function login(email, password, usertype, link) {

let expiredDate = new Date(token.exp * 1000);
Cookies.set("token", token.token, { expires: expiredDate });
window.location.href = link;
goto(link);
};

export async function register(email, password, phone, usertype) {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/components/Navbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
NavLink,
} from "@sveltestrap/sveltestrap";
import { user } from "$lib/store.js";
import { goto } from "$app/navigation";
let isOpen = false;
export let size = "md";
function logout() {
Cookies.remove("token");
window.location.href = "/";
goto("/");
}
function handleUpdate(event) {
Expand Down
8 changes: 1 addition & 7 deletions src/routes/(admin)/+layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@ export const ssr = false
import Cookies from 'js-cookie';
import { error } from '@sveltejs/kit';
import { invoke } from '@tauri-apps/api/tauri';
import { user, theme } from '$lib/store';
import { user } from '$lib/store';
import { get } from 'svelte/store';
import { Styles } from '@sveltestrap/sveltestrap';
import Spinner from '$lib/components/Spinner.svelte';

export async function load() {
const styles = new Styles({ target: document.head, props: { theme: get(theme) } });
const spinner = new Spinner({ target: document.body });
let token = Cookies.get('token');
if (!token) return error(403, 'You are not logged in or your session has expired');
user.set(await invoke('check_auth', { token }));
if (get(user).usertype != 'admin') {
return error(403, 'Unauthorized');
}
styles.$destroy();
spinner.$destroy();
}
9 changes: 1 addition & 8 deletions src/routes/(authed)/+layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@ export const ssr = false
import Cookies from 'js-cookie';
import { redirect } from '@sveltejs/kit';
import { invoke } from '@tauri-apps/api/tauri';
import { theme, user } from '$lib/store';
import { get } from 'svelte/store';
import Spinner from '$lib/components/Spinner.svelte';
import { Styles } from '@sveltestrap/sveltestrap';
import { user } from '$lib/store';

export async function load() {
const styles = new Styles({ target: document.head, props: { theme: get(theme) } });
const spinner = new Spinner({ target: document.body });
let token = Cookies.get('token');
if (!token) {
return redirect(301, '/');
}
user.set(await invoke('check_auth', { token }));
styles.$destroy();
spinner.$destroy();
}
12 changes: 12 additions & 0 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<script>
import { theme } from "$lib/store";
import { Styles } from "@sveltestrap/sveltestrap";
import { onNavigate } from "$app/navigation";
onNavigate((navigation) => {
if (!document.startViewTransition) return;
return new Promise((resolve) => {
document.startViewTransition(async () => {
resolve();
await navigation.complete;
});
});
});
</script>

<Styles theme={$theme} />
Expand Down

0 comments on commit 4d07185

Please sign in to comment.