Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
only load profile if logged in; load local loadout without making a r…
Browse files Browse the repository at this point in the history
…equest;
  • Loading branch information
lmssiehdev committed Sep 10, 2024
1 parent e771ee1 commit 923bc6c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
31 changes: 18 additions & 13 deletions client/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import $ from "jquery";
import { util } from "../../shared/utils/util";
import { api } from "./api";
import type { ConfigManager } from "./config";
import { helpers } from "./helpers";
import type { Item } from "./ui/loadoutMenu";
import loadouts, { type ItemStatus, type Loadout } from "./ui/loadouts";

Expand Down Expand Up @@ -146,10 +147,16 @@ export class Account {
if (this.config.get("sessionCookie")) {
this.setSessionCookies();
}
// if (helpers.getCookie("app-data")) {
this.login();
// this.loadProfile();
// }
if (helpers.getCookie("app-data")) {
this.login();
} else {
this.emit("request", this);
this.emit("items", []);

const storedLoadout = this.config.get("loadout");
this.loadout = util.mergeDeep({}, loadouts.defaultLoadout(), storedLoadout);
this.emit("loadout", this.loadout);
}
}

setSessionCookies() {
Expand Down Expand Up @@ -187,10 +194,10 @@ export class Account {
}

login() {
// if (helpers.getCookie("app-data")) {
this.loadProfile();
this.getPass(true);
// }
if (helpers.getCookie("app-data")) {
this.loadProfile();
this.getPass(true);
}
}

logout() {
Expand All @@ -203,7 +210,6 @@ export class Account {

loadProfile() {
this.loggingIn = !this.loggedIn;
let _loadout = {};
this.ajaxRequest("/api/user/profile", (err, data) => {
const a = this.loggingIn;
this.loggingIn = false;
Expand Down Expand Up @@ -233,10 +239,6 @@ export class Account {
}
this.emit("items", this.items);
});

const storedLoadout = this.config.get("loadout");
this.loadout = util.mergeDeep({}, loadouts.defaultLoadout(), storedLoadout);
this.emit("loadout", this.loadout);
}

resetStats() {
Expand Down Expand Up @@ -289,6 +291,9 @@ export class Account {
this.loadout = loadout;
this.emit("loadout", this.loadout);
this.config.set("loadout", loadout);

if ( !helpers.getCookie("app-data") ) return;

this.ajaxRequest(
"/api/user/loadout",
{
Expand Down
3 changes: 2 additions & 1 deletion server/src/api/routes/user/UserRouter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { zValidator } from "@hono/zod-validator";
import { and, eq, inArray } from "drizzle-orm";
import { Hono } from "hono";
import { deleteCookie } from "hono/cookie";
import { z } from "zod";
import type { Context } from "../..";
import { OutfitDefs } from "../../../../../shared/defs/gameObjects/outfitDefs";
Expand Down Expand Up @@ -168,7 +169,7 @@ UserRouter.post(
UserRouter.post("/logout", AuthMiddleware, async (c) => {
try {
const session = c.get("session")!;

deleteCookie(c, "app-data");
await lucia.invalidateSession(session.id);
c.header("Set-Cookie", lucia.createBlankSessionCookie().serialize(), {
append: true,
Expand Down
2 changes: 2 additions & 0 deletions server/src/api/routes/user/auth/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ GithubRouter.get("/callback", async (c) => {
where: eq(usersTable.auth_id, githubUser.id),
});

setCookie(c, "app-data", "1");

if (existingUser) {
setUserCookie(existingUser.id, c);
return c.redirect("/");
Expand Down

0 comments on commit 923bc6c

Please sign in to comment.