haha bye claiming (for now)
All checks were successful
deploy / deploy (push) Successful in 44s

This commit is contained in:
Lee 2023-10-20 14:32:22 +01:00
parent f548902f13
commit 6513ba3e15
2 changed files with 4 additions and 31 deletions

@ -10,7 +10,7 @@ import { ScoresaberPlayer } from "@/schemas/scoresaber/player";
import { ScoresaberPlayerScore } from "@/schemas/scoresaber/playerScore"; import { ScoresaberPlayerScore } from "@/schemas/scoresaber/playerScore";
import { formatNumber } from "@/utils/number"; import { formatNumber } from "@/utils/number";
import { fetchScores, getPlayerInfo } from "@/utils/scoresaber/api"; import { fetchScores, getPlayerInfo } from "@/utils/scoresaber/api";
import { GlobeAsiaAustraliaIcon, HomeIcon } from "@heroicons/react/20/solid"; import { GlobeAsiaAustraliaIcon } from "@heroicons/react/20/solid";
import moment from "moment"; import moment from "moment";
import Image from "next/image"; import Image from "next/image";
import { useCallback, useEffect, useState } from "react"; import { useCallback, useEffect, useState } from "react";
@ -70,15 +70,6 @@ export default function Player({ params }: { params: { id: string } }) {
[params.id, scores], [params.id, scores],
); );
function claimProfile() {
// set cookie to claim profile
document.cookie = `profile=${params.id};path=/`;
}
function isClaimedProfile() {
return document.cookie.includes(`profile=${params.id}`);
}
useEffect(() => { useEffect(() => {
if (!params.id) { if (!params.id) {
setError(true); setError(true);
@ -141,15 +132,6 @@ export default function Player({ params }: { params: { id: string } }) {
<div> <div>
<div className="flex flex-col items-center gap-2"> <div className="flex flex-col items-center gap-2">
<Avatar url={playerData.profilePicture} label="Avatar" /> <Avatar url={playerData.profilePicture} label="Avatar" />
{!isClaimedProfile() && (
<button onClick={claimProfile}>
<HomeIcon
title="Set as your profile"
width={24}
height={24}
/>
</button>
)}
</div> </div>
</div> </div>
<div className="flex flex-col items-center gap-2 xs:items-start"> <div className="flex flex-col items-center gap-2 xs:items-start">
@ -222,7 +204,7 @@ export default function Player({ params }: { params: { id: string } }) {
return ( return (
<div <div
className="grid grid-cols-[.9fr_6fr_3fr] p-2" className="grid grid-cols-[1fr_6fr_3fr] p-2"
key={id} key={id}
> >
<div className="flex flex-col items-center justify-center"> <div className="flex flex-col items-center justify-center">

@ -2,20 +2,11 @@ import type { NextRequest } from "next/server";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export function middleware(request: NextRequest) { export function middleware(request: NextRequest) {
console.log(request.cookies); // todo: make this redirect to the users profile if they have a profile selected
const profileCookie = request.cookies.get("profile");
if (request.nextUrl.pathname == "/") { if (request.nextUrl.pathname == "/") {
// Has a claimed profile cookie
if (profileCookie) {
const id = profileCookie.value;
return NextResponse.redirect(new URL(`/profile/${id}`, request.url));
} else {
// User has not claimed a profile
return NextResponse.redirect(new URL("/search", request.url)); return NextResponse.redirect(new URL("/search", request.url));
} }
} }
}
export const config = { export const config = {
matcher: "/((?!api|_next/static|_next/image|favicon.ico).*)", matcher: "/((?!api|_next/static|_next/image|favicon.ico).*)",