bugfixing
This commit is contained in:
parent
881886e93d
commit
6d4ceb21bd
@ -1,22 +1,9 @@
|
|||||||
import { sequence } from "@sveltejs/kit/hooks";
|
import { sequence } from "@sveltejs/kit/hooks";
|
||||||
import PocketBase from "pocketbase";
|
import PocketBase from "pocketbase";
|
||||||
import { serializeNonPOJOs } from "$lib/utils";
|
import { serializeNonPOJOs } from "$lib/utils";
|
||||||
//import geoip from "geoip-lite";
|
|
||||||
|
|
||||||
export const handle = sequence(async ({ event, resolve }) => {
|
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
|
// 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;
|
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;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
onmessage = async (event: MessageEvent) => {
|
onmessage = async (event: MessageEvent) => {
|
||||||
const data = event.data?.message;
|
const data = event.data?.message;
|
||||||
|
let output = {}
|
||||||
try {
|
try {
|
||||||
const [notificationList] = await Promise.all([loadNotifications()]);
|
const [notificationList] = await Promise?.all([loadNotifications()]);
|
||||||
const numberOfUnreadNotification = notificationList.filter(
|
const numberOfUnreadNotification = notificationList?.filter(
|
||||||
(item?) => !item?.readed,
|
(item?) => !item?.readed,
|
||||||
);
|
);
|
||||||
const hasUnreadElement =
|
const hasUnreadElement =
|
||||||
numberOfUnreadNotification?.length !== 0 ? true : false;
|
numberOfUnreadNotification?.length !== 0 ? true : false;
|
||||||
const output = {
|
output = {
|
||||||
notificationList,
|
notificationList,
|
||||||
hasUnreadElement,
|
hasUnreadElement,
|
||||||
numberOfUnreadNotification,
|
numberOfUnreadNotification,
|
||||||
@ -30,7 +30,8 @@ onmessage = async (event: MessageEvent) => {
|
|||||||
|
|
||||||
postMessage({ message: "success", output });
|
postMessage({ message: "success", output });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
postMessage({ message: "error", e });
|
console.log(e)
|
||||||
|
postMessage({ message: "error", output });
|
||||||
}
|
}
|
||||||
// Sending data back to the main thread
|
// Sending data back to the main thread
|
||||||
//postMessage({ message: 'Data received in the worker', ticker, apiURL });
|
//postMessage({ message: 'Data received in the worker', ticker, apiURL });
|
||||||
|
|||||||
@ -170,8 +170,10 @@
|
|||||||
typeof data?.cookieConsent !== "undefined" ? false : true;
|
typeof data?.cookieConsent !== "undefined" ? false : true;
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await Promise.all([checkMarketHour(), loadWorker()]);
|
if (data?.user?.id) {
|
||||||
|
await loadWorker();
|
||||||
|
}
|
||||||
|
await checkMarketHour();
|
||||||
if ($showCookieConsent === true) {
|
if ($showCookieConsent === true) {
|
||||||
Cookie = (await import("$lib/components/Cookie.svelte")).default;
|
Cookie = (await import("$lib/components/Cookie.svelte")).default;
|
||||||
}
|
}
|
||||||
@ -180,7 +182,7 @@
|
|||||||
await detectSWUpdate();
|
await detectSWUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Clear all the cache every 20 min
|
// Clear all the cache every 20 min
|
||||||
const interval = setInterval(
|
const interval = setInterval(
|
||||||
() => {
|
() => {
|
||||||
clearCache();
|
clearCache();
|
||||||
|
|||||||
@ -100,7 +100,7 @@ export const actions = {
|
|||||||
maxAge: 60,
|
maxAge: 60,
|
||||||
});
|
});
|
||||||
|
|
||||||
redirect(302, authProviderRedirect);
|
redirect(303, authProviderRedirect);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { redirect } from "@sveltejs/kit";
|
import { redirect } from "@sveltejs/kit";
|
||||||
|
import { serializeNonPOJOs } from "$lib/utils";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -46,10 +47,11 @@ export const GET = async ({ locals, url, cookies }) => {
|
|||||||
try {
|
try {
|
||||||
//
|
//
|
||||||
|
|
||||||
newUser = await locals.pb
|
await locals.pb
|
||||||
?.collection("users")
|
?.collection("users")
|
||||||
.authWithOAuth2Code(provider.name, code, expectedVerifier, redirectURL);
|
.authWithOAuth2Code(provider.name, code, expectedVerifier, redirectURL);
|
||||||
|
|
||||||
|
|
||||||
//oauthUsername = generateUsername(newUser['meta']['name'].split(' ').join('')).toLowerCase();
|
//oauthUsername = generateUsername(newUser['meta']['name'].split(' ').join('')).toLowerCase();
|
||||||
|
|
||||||
// Check if user was created or existed already
|
// Check if user was created or existed already
|
||||||
@ -70,11 +72,8 @@ export const GET = async ({ locals, url, cookies }) => {
|
|||||||
if (cookies?.get("path")) {
|
if (cookies?.get("path")) {
|
||||||
redirect(301, cookies?.get("path"));
|
redirect(301, cookies?.get("path"));
|
||||||
} else {
|
} 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(
|
const targetItem = authMethods?.providers?.findIndex(
|
||||||
(item) => item?.name === providerSelected,
|
(item) => item?.name === providerSelected,
|
||||||
);
|
);
|
||||||
|
|
||||||
//console.log("==================")
|
//console.log("==================")
|
||||||
//console.log(authMethods.authProviders)
|
//console.log(authMethods.authProviders)
|
||||||
//console.log('target item is: ', targetItem)
|
//console.log('target item is: ', targetItem)
|
||||||
@ -135,6 +134,6 @@ export const actions = {
|
|||||||
maxAge: 60,
|
maxAge: 60,
|
||||||
});
|
});
|
||||||
|
|
||||||
redirect(302, authProviderRedirect);
|
redirect(303, authProviderRedirect);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user