add playerId cookie to set where the landing page should be
All checks were successful
deploy / deploy (push) Successful in 4m59s
All checks were successful
deploy / deploy (push) Successful in 4m59s
This commit is contained in:
@ -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") {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user