Skip to content

Commit

Permalink
pass language with params
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartaithan committed Feb 10, 2024
1 parent 6dc923e commit 779b2d2
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions app/api/games/library/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import {
type UserTitles,
type TitleTrophiesOptions,
} from "@/models/TrophyModel";
import { createClient } from "@/utils/supabase/server";
import { cookies } from "next/headers";
import { type AuthorizationPayload, getUserTitles } from "psn-api";

export const GET = async (req: Request): Promise<Response> => {
const { searchParams } = new URL(req.url);
const limit = searchParams.get("limit");
const offset = searchParams.get("offset");
const language = searchParams.get("language");

const access_token = cookies().get("psn-access-token")?.value;
if (typeof access_token !== "string") {
Expand All @@ -20,31 +20,10 @@ export const GET = async (req: Request): Promise<Response> => {
);
}

const supabase = createClient(cookies());
const {
data: { user },
error: userError,
} = await supabase.auth.getUser();
if (userError !== null || user === null) {
console.error("unable to get user", userError);
return Response.json({ message: "Unable to get user" }, { status: 400 });
}

const { data: profile, error: profileError } = await supabase
.from("profiles")
.select("username, language")
.eq("id", user.id)
.single();
if (profileError !== null || profile === null) {
console.error("unable to get profile", profileError);
return Response.json({ message: "Unable to get profile" }, { status: 400 });
}

const auth: AuthorizationPayload = { accessToken: access_token };

const language = profile.language ?? "en-US";
const options: Partial<TitleTrophiesOptions> = {
headerOverrides: { "Accept-Language": language },
headerOverrides: { "Accept-Language": language ?? "en-US" },
limit: limit != null ? Number(limit) : 10,
offset: offset != null ? Number(offset) : 0,
};
Expand Down

0 comments on commit 779b2d2

Please sign in to comment.