Change planetid cookie to currentPlanet

This commit is contained in:
Aelita4 2024-11-03 23:22:21 +01:00
parent 91cafb2bf3
commit 1bbc55563d
Signed by: Aelita4
GPG Key ID: E44490C2025906C1
8 changed files with 8 additions and 8 deletions

View File

@ -9,7 +9,7 @@ const resourceTypes = await getAllResources();
const lang = await getLocales(Astro.cookies.get('language')?.value ?? await getHighestWeightedLanguage(Astro.request.headers.get('accept-language')));
const planetId = new ObjectId(Astro.cookies.get('planetid')?.value ?? '');
const planetId = new ObjectId(Astro.cookies.get('currentPlanet')?.value ?? '');
const planet = locationManager.getPlanet(planetId);

View File

@ -23,7 +23,7 @@ const locale = Astro.cookies.get('language')?.value ?? await getHighestWeightedL
const lang = await getLocales(locale);
const planetId = Astro.cookies.get('planetid')?.value ?? "";
const planetId = Astro.cookies.get('currentPlanet')?.value ?? "";
if(planetId === "") return "No planet selected";
const planet = locationManager.getPlanet(new ObjectId(planetId));

View File

@ -19,7 +19,7 @@ if(checkUser === null || checkUser.username !== username) return Astro.redirect(
const user = locationManager.getUser(checkUser._id);
if(!user) return Astro.redirect('/logout');
const planetId = Astro.cookies.get('planetid')?.value ?? "";
const planetId = Astro.cookies.get('currentPlanet')?.value ?? "";
if(planetId === "") return "No planet selected";
const planet = locationManager.getPlanet(new ObjectId(planetId));

View File

@ -13,8 +13,8 @@ if(loggedToken === null || username === "") return Astro.redirect('/logout');
const checkUser = await getUserByAccessToken(loggedToken);
if(checkUser === null || checkUser.username !== username) return Astro.redirect('/logout');
const currentPlanetId = Astro.cookies.get('planetid')?.value ?? null;
if(currentPlanetId === null) return Astro.redirect('/game/logout');
const currentPlanetId = Astro.cookies.get('currentPlanet')?.value ?? null;
const currentPlanet = locationManager.getPlanet(new ObjectId(currentPlanetId));
if(currentPlanet === undefined) {
Astro.cookies.delete('planetid');

View File

@ -16,7 +16,7 @@ if(loggedToken === null || username === "") return Astro.redirect('/logout');
const checkUser = await getUserByAccessToken(loggedToken);
if(checkUser === null || checkUser.username !== username) return Astro.redirect('/logout');
const planetId = Astro.cookies.get('planetid')?.value ?? "";
const planetId = Astro.cookies.get('currentPlanet')?.value ?? "";
if(planetId === "") return Astro.redirect('/logout');
if(Astro.request.method === "POST") {

View File

@ -18,7 +18,7 @@ if(checkUser === null || checkUser.username !== username) return Astro.redirect(
const ships = await getAllShips();
const planetId = Astro.cookies.get('planetid')?.value ?? "";
const planetId = Astro.cookies.get('currentPlanet')?.value ?? "";
if(planetId === "") {
console.error("No planet selected");
return Astro.redirect('/logout');

View File

@ -28,7 +28,7 @@ if(Astro.request.method === "POST") {
const selectedPlanetId = (await Astro.request.formData()).get('planetId') as string | null;
if(selectedPlanetId !== null) {
Astro.cookies.set('planetid', selectedPlanetId, {
Astro.cookies.set('currentPlanet', selectedPlanetId, {
path: '/',
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
sameSite: 'lax',

View File

@ -71,7 +71,7 @@ if(Astro.request.method === "POST") {
secure: true
});
Astro.cookies.set("planetid", user.mainPlanet._id, {
Astro.cookies.set("currentPlanet", user.mainPlanet._id, {
path: "/",
maxAge: sessionTime,
sameSite: "lax",