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

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

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

@ -3,11 +3,18 @@ import { NextResponse } from "next/server";
export function middleware(request: NextRequest) { export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl; 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 == "/") { if (pathname == "/") {
if (playerIdCookie) {
return NextResponse.redirect(
new URL(`/player/${playerIdCookie}`, request.url),
);
} else {
return NextResponse.redirect(new URL("/search", request.url)); return NextResponse.redirect(new URL("/search", request.url));
} }
}
if (pathname == "/ranking/global") { if (pathname == "/ranking/global") {
return NextResponse.redirect(new URL("/ranking/global/1", request.url)); return NextResponse.redirect(new URL("/ranking/global/1", request.url));

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