diff options
-rw-r--r-- | api/client_test/index.html | 22 | ||||
-rw-r--r-- | api/src/Server.ts | 2 | ||||
-rw-r--r-- | api/src/routes/auth/login.ts | 4 |
3 files changed, 19 insertions, 9 deletions
diff --git a/api/client_test/index.html b/api/client_test/index.html index 7aa4490a..fb2e0a2d 100644 --- a/api/client_test/index.html +++ b/api/client_test/index.html @@ -36,9 +36,16 @@ HTML_TIMESTAMP: Date.now(), ALGOLIA_KEY: "aca0d7082e4e63af5ba5917d5e96bed0" }; + const localStorage = window.localStorage; // TODO: remote auth // window.GLOBAL_ENV.REMOTE_AUTH_ENDPOINT = window.GLOBAL_ENV.GATEWAY_ENDPOINT.replace(/wss?:/, ""); - localStorage.removeItem("gatewayURL"); + localStorage.setItem("gatewayURL", window.GLOBAL_ENV.GATEWAY_ENDPOINT); + localStorage.setItem( + "DeveloperOptionsStore", + `{"trace":false,"canary":false,"logGatewayEvents":true,"logOverlayEvents":true,"logAnalyticsEvents":true,"sourceMapsEnabled":false,"axeEnabled":false}` + ); + + // Auto register guest account: const token = JSON.parse(localStorage.getItem("token")); if (!token) { fetch(`${window.GLOBAL_ENV.API_ENDPOINT}/auth/register`, { @@ -47,13 +54,14 @@ body: JSON.stringify({ username: "Anonymous", consent: true }) }) .then((x) => x.json()) - .then((x) => localStorage.setItem("token", `"${x.token}"`)); + .then((x) => { + localStorage.setItem("token", `"${x.token}"`); + if (!window.localStorage) { + // client already loaded -> need to reload to apply the newly registered user token + location.reload(); + } + }); } - - localStorage.setItem( - "DeveloperOptionsStore", - `{"trace":false,"canary":false,"logGatewayEvents":true,"logOverlayEvents":true,"logAnalyticsEvents":true,"sourceMapsEnabled":false,"axeEnabled":false}` - ); </script> <script src="/assets/479a2f1e7d625dc134b9.js"></script> <script src="/assets/a15fd133a1d2d77a2424.js"></script> diff --git a/api/src/Server.ts b/api/src/Server.ts index a16a61f8..12c1d6b4 100644 --- a/api/src/Server.ts +++ b/api/src/Server.ts @@ -13,6 +13,7 @@ import { initRateLimits } from "./middlewares/RateLimit"; import TestClient from "./middlewares/TestClient"; import { initTranslation } from "./middlewares/Translation"; import morgan from "morgan"; +import { initInstance } from "./util/Instance"; export interface FosscordServerOptions extends ServerOptions {} @@ -37,6 +38,7 @@ export class FosscordServer extends Server { await initDatabase(); await Config.init(); await initEvent(); + await initInstance(); /* DOCUMENTATION: uses LOG_REQUESTS environment variable diff --git a/api/src/routes/auth/login.ts b/api/src/routes/auth/login.ts index ff04f8aa..a89721ea 100644 --- a/api/src/routes/auth/login.ts +++ b/api/src/routes/auth/login.ts @@ -1,7 +1,7 @@ import { Request, Response, Router } from "express"; -import { FieldErrors, route } from "@fosscord/api"; +import { route } from "@fosscord/api"; import bcrypt from "bcrypt"; -import { Config, User, generateToken, adjustEmail } from "@fosscord/util"; +import { Config, User, generateToken, adjustEmail, FieldErrors } from "@fosscord/util"; const router: Router = Router(); export default router; |