Next.js Discord

Discord Forum

How to refactor getToken to "app" ?

Answered
Asiatic Lion posted this in #help-forum
Open in Discord
Asiatic LionOP
import { NextRequest } from "next/server";
import { getToken } from "next-auth/jwt";

import { User } from "../features/users/types";

export const validateToken = async (req: Request) => {
  const token = await getToken({ req });
  if (!token) return false;

  const userId = req.body?.userId ?? req.query?.userId;
  if (!userId) return false;

  const tokenUser = token.user as User;
  return token && tokenUser.id === Number(userId);
};


get an error on getToken, trying to refactor to "app"
Answered by Black carp
Change the type of req: NextRequest I believe
View full answer

11 Replies

Answer
Asiatic LionOP
how to set as answer?
there no "apps"
Right click the answer message
There is “apps” there
Or tap and hold if you’re on mobile
Asiatic LionOP
im on pc, i dont see any apps
Black carp
Not sure why u dont get it🧐
I’ll let the developer know