bugfixing
This commit is contained in:
parent
881886e93d
commit
6d4ceb21bd
@ -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;
|
||||
|
||||
@ -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 });
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ export const actions = {
|
||||
maxAge: 60,
|
||||
});
|
||||
|
||||
redirect(302, authProviderRedirect);
|
||||
redirect(303, authProviderRedirect);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@ -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);
|
||||
};
|
||||
|
||||
@ -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);
|
||||
},
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user