add playerId cookie to set where the landing page should be
All checks were successful
deploy / deploy (push) Successful in 4m59s

This commit is contained in:
Lee 2023-10-24 07:47:11 +01:00
parent f2f332582b
commit dc3d5b9b33
4 changed files with 22 additions and 2 deletions

6
package-lock.json generated
View File

@ -8,6 +8,7 @@
"name": "scoresaber-reloadedv2",
"version": "0.1.0",
"dependencies": {
"@boiseitguru/cookie-cutter": "^0.2.1",
"@heroicons/react": "^2.0.18",
"@sentry/nextjs": "^7.74.1",
"bluebird": "^3.7.2",
@ -76,6 +77,11 @@
"node": ">=6.9.0"
}
},
"node_modules/@boiseitguru/cookie-cutter": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/@boiseitguru/cookie-cutter/-/cookie-cutter-0.2.1.tgz",
"integrity": "sha512-MLYTqtyECvjq+Wjq2k++bXReIlClTrtpSWSXeamp868MWKggn6SanFBZRVhI61isf3ETuvmDJObexW36Ck4SCQ=="
},
"node_modules/@eslint-community/eslint-utils": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz",

View File

@ -9,6 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@boiseitguru/cookie-cutter": "^0.2.1",
"@heroicons/react": "^2.0.18",
"@sentry/nextjs": "^7.74.1",
"bluebird": "^3.7.2",

View File

@ -3,10 +3,17 @@ import { NextResponse } from "next/server";
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;
const cookies = request.cookies;
// todo: make this redirect to the users profile if they have a profile selected
const playerIdCookie = cookies.get("playerId");
if (pathname == "/") {
return NextResponse.redirect(new URL("/search", request.url));
if (playerIdCookie) {
return NextResponse.redirect(
new URL(`/player/${playerIdCookie}`, request.url),
);
} else {
return NextResponse.redirect(new URL("/search", request.url));
}
}
if (pathname == "/ranking/global") {

View File

@ -9,6 +9,9 @@ import { createJSONStorage, persist } from "zustand/middleware";
import { IDBStorage } from "./IndexedDBStorage";
import { useScoresaberScoresStore } from "./scoresaberScoresStore";
// it has no typescript support
const cookieCutter = require("@boiseitguru/cookie-cutter");
interface SettingsStore {
player: ScoresaberPlayer | undefined;
friends: ScoresaberPlayer[];
@ -40,6 +43,8 @@ export const useSettingsStore = create<SettingsStore>()(
set({
player: playerData,
});
cookieCutter.set("playerId", playerData.id);
},
async addFriend(friendId: string) {
@ -97,6 +102,7 @@ export const useSettingsStore = create<SettingsStore>()(
if (newPlayer != undefined && newPlayer != null) {
console.log("Updated player data for", newPlayer.name);
set({ player: newPlayer });
cookieCutter.set("playerId", newPlayer.id);
}
}