Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueBurger committed Nov 6, 2023
1 parent 2c8d2fc commit 46a7956
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
1 change: 0 additions & 1 deletion Integrator/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
build
.gradle
.idea
gradle
Binary file added Integrator/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions Integrator/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
10 changes: 8 additions & 2 deletions Web/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { computed, onMounted, onUnmounted, provide, Ref, ref } from "vue";
import { getActivePinia, Pinia, Store } from "pinia";
import { computed, onMounted, onUnmounted, provide, Ref, ref, watch } from "vue";
import { getActivePinia, Pinia, Store, storeToRefs } from "pinia";
import { RouteLocationNormalized, useRouter } from "vue-router";
import type { AuthS2C } from "@share/Auth";
Expand Down Expand Up @@ -135,6 +135,12 @@ let users = ref(new Map<string, User>());
provide("users", users);
let loginMsg = ref("");
const userRefs = storeToRefs(user);
watch(userRefs.failedLogin, (newVal) => {
if(newVal) {
showLoginScreen.value = true;
}
});
ws.listenForEvent("loginFailed", (data: AuthS2C) => {
console.log("Login failed: " + data.message)
loginMsg.value = data.message as string;
Expand Down
16 changes: 13 additions & 3 deletions Web/src/stores/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { Permission, hasServerPermission as _hasServerPermission, hasPermission
import { Server } from "@share/Server";
import { useServers } from "./servers";
import { RequestResponses } from "@share/Requests";
import { useWS } from "./ws";

export const useUser = defineStore("user", () => {
const user: Ref<User | undefined> = ref();
const failedLogin: Ref<boolean> = ref(false);
function logout() {
if(user.value == undefined) throw new Error("already logged out");
localStorage.removeItem("token");
Expand All @@ -26,7 +28,13 @@ export const useUser = defineStore("user", () => {
async function autoLogin() {
let testToken = localStorage.getItem("token")
if (testToken) {
loginToken(testToken);
try {
await loginToken(testToken);
failedLogin.value = true;
} catch {
localStorage.removeItem("token");
return true;
}
return true;
} return false;
}
Expand All @@ -43,6 +51,8 @@ export const useUser = defineStore("user", () => {
}

function handleLoginPacket(packet: RequestResponses["auth"]) {
failedLogin.value = true;
localStorage.setItem("token", packet.user.token);
if(packet.servers) {
let servers = useServers();
servers.addServers(packet.servers);
Expand All @@ -53,5 +63,5 @@ export const useUser = defineStore("user", () => {
}
user.value = packet.user;
}
return { user, logout, hasPermission, hasServerPermission, autoLogin, resetUser, loginToken, loginUsernamePass }
})
return { user, logout, hasPermission, hasServerPermission, autoLogin, resetUser, loginToken, loginUsernamePass, failedLogin }
});

0 comments on commit 46a7956

Please sign in to comment.