bugfixing

This commit is contained in:
MuslemRahimi 2024-12-11 10:27:40 +01:00
parent 881886e93d
commit 6d4ceb21bd
6 changed files with 19 additions and 31 deletions

View File

@ -1,22 +1,9 @@
import { sequence } from "@sveltejs/kit/hooks";
import PocketBase from "pocketbase";
import { serializeNonPOJOs } from "$lib/utils";
//import geoip from "geoip-lite";
export const handle = sequence(async ({ event, resolve }) => {
/*
const ip =
event.request.headers.get("x-forwarded-for")?.split(",")[0] ||
event.getClientAddress();
let isUS = false;
if (ip) {
const geoData = geoip?.lookup(ip);
if (geoData && geoData.country === "US") {
isUS = true;
}
}
*/
// Use a ternary operator instead of the logical OR for better compatibility
const pbURL = import.meta.env.VITE_USEAST_POCKETBASE_URL; //isUS ? import.meta.env.VITE_USEAST_POCKETBASE_URL : import.meta.env.VITE_EU_POCKETBASE_URL;

View File

@ -8,21 +8,21 @@ async function loadNotifications() {
},
});
const output = await response.json();
const output = await response?.json() || [];
return output;
}
onmessage = async (event: MessageEvent) => {
const data = event.data?.message;
let output = {}
try {
const [notificationList] = await Promise.all([loadNotifications()]);
const numberOfUnreadNotification = notificationList.filter(
const [notificationList] = await Promise?.all([loadNotifications()]);
const numberOfUnreadNotification = notificationList?.filter(
(item?) => !item?.readed,
);
const hasUnreadElement =
numberOfUnreadNotification?.length !== 0 ? true : false;
const output = {
output = {
notificationList,
hasUnreadElement,
numberOfUnreadNotification,
@ -30,7 +30,8 @@ onmessage = async (event: MessageEvent) => {
postMessage({ message: "success", output });
} catch (e) {
postMessage({ message: "error", e });
console.log(e)
postMessage({ message: "error", output });
}
// Sending data back to the main thread
//postMessage({ message: 'Data received in the worker', ticker, apiURL });

View File

@ -170,8 +170,10 @@
typeof data?.cookieConsent !== "undefined" ? false : true;
onMount(async () => {
await Promise.all([checkMarketHour(), loadWorker()]);
if (data?.user?.id) {
await loadWorker();
}
await checkMarketHour();
if ($showCookieConsent === true) {
Cookie = (await import("$lib/components/Cookie.svelte")).default;
}
@ -180,7 +182,7 @@
await detectSWUpdate();
}
//Clear all the cache every 20 min
// Clear all the cache every 20 min
const interval = setInterval(
() => {
clearCache();

View File

@ -100,7 +100,7 @@ export const actions = {
maxAge: 60,
});
redirect(302, authProviderRedirect);
redirect(303, authProviderRedirect);
},
};

View File

@ -1,4 +1,5 @@
import { redirect } from "@sveltejs/kit";
import { serializeNonPOJOs } from "$lib/utils";
@ -46,10 +47,11 @@ export const GET = async ({ locals, url, cookies }) => {
try {
//
newUser = await locals.pb
await locals.pb
?.collection("users")
.authWithOAuth2Code(provider.name, code, expectedVerifier, redirectURL);
//oauthUsername = generateUsername(newUser['meta']['name'].split(' ').join('')).toLowerCase();
// Check if user was created or existed already
@ -70,11 +72,8 @@ export const GET = async ({ locals, url, cookies }) => {
if (cookies?.get("path")) {
redirect(301, cookies?.get("path"));
} else {
redirect(301, "/");
redirect(303, "/");
}
//Login user automatically
//const avatarUrl = newUser['meta']['avatarUrl'];
//console.log(avatarUrl);
};

View File

@ -91,7 +91,6 @@ export const actions = {
const targetItem = authMethods?.providers?.findIndex(
(item) => item?.name === providerSelected,
);
//console.log("==================")
//console.log(authMethods.authProviders)
//console.log('target item is: ', targetItem)
@ -135,6 +134,6 @@ export const actions = {
maxAge: 60,
});
redirect(302, authProviderRedirect);
redirect(303, authProviderRedirect);
},
};