401 error Next-Auth
Unanswered
Red-billed Tropicbird posted this in #help-forum
Red-billed TropicbirdOP
I am making a call to use stripe checkout but am getting unauthroized even though I am signed in
Here is my repo for further:
https://github.com/Kanwar-Ghuman/ReZume
Here is my repo for further:
https://github.com/Kanwar-Ghuman/ReZume
26 Replies
Red-billed TropicbirdOP
Here is where the erro ris occruing:
export async function POST(
req: Request,
{ params }: { params: { resumeId: string } }
) {
try {
const user = await auth()
console.log(user)
if (!user || !user.user.id) {
return new NextResponse("Unauthorized", { status: 401 })
}
export async function POST(
req: Request,
{ params }: { params: { resumeId: string } }
) {
try {
const user = await auth()
console.log(user)
if (!user || !user.user.id) {
return new NextResponse("Unauthorized", { status: 401 })
}
Red-billed TropicbirdOP
Here is what it logs:
{
user: {
name: 'Kanwar Ghuman',
email: 'ghumankm@gmail.com',
image: 'https://lh3.googleusercontent.com/a/ACg8ocIq4p0nOFGpvCZWlx5jbnuoXjwg7Eyo6iGEjcfkvK5Vgqmm6g=s96-c',
role: 'USER'
},
expires: '2024-07-10T20:25:47.359Z'
{
user: {
name: 'Kanwar Ghuman',
email: 'ghumankm@gmail.com',
image: 'https://lh3.googleusercontent.com/a/ACg8ocIq4p0nOFGpvCZWlx5jbnuoXjwg7Eyo6iGEjcfkvK5Vgqmm6g=s96-c',
role: 'USER'
},
expires: '2024-07-10T20:25:47.359Z'
Sun bear
Looks like the problem is here
There is no user.user.id
if (!user || !user.user.id)There is no user.user.id
Red-billed TropicbirdOP
IT autocompletes that do you want see my prisma schema
Red-billed TropicbirdOP
The issue is that I get this error :
https://nextjs-forum.com/post/1249812320348012684
https://nextjs-forum.com/post/1249812320348012684
And that messes up my authentication
the user.user.id exists
Red-billed TropicbirdOP
?
Red-billed TropicbirdOP
Do you have any idea why I would get this error on the adapter:
next-auth.d.ts(7, 5): 'role' is declared here.
(property) adapter?: Adapter | undefined
here is the file
next-auth.d.ts(7, 5): 'role' is declared here.
(property) adapter?: Adapter | undefined
here is the file
Red-billed TropicbirdOP
@Sun bear ?
@Red-billed Tropicbird Here is what it logs:
{
user: {
name: 'Kanwar Ghuman',
email: 'ghumankm@gmail.com',
image: 'https://lh3.googleusercontent.com/a/ACg8ocIq4p0nOFGpvCZWlx5jbnuoXjwg7Eyo6iGEjcfkvK5Vgqmm6g=s96-c',
role: 'USER'
},
expires: '2024-07-10T20:25:47.359Z'
Sun bear
Based on this log there is no user.user.id so the 401 is what you get.
Red-billed TropicbirdOP
I am confused as in my prisma.schema it is all set up correctly I believe it has to do with the adapter error but cannot find out why
Here is the schema
Thats the scehma
Oh do you think it is due to the Account and User schema?
@Red-billed Tropicbird Here is where the erro ris occruing:
export async function POST(
req: Request,
{ params }: { params: { resumeId: string } }
) {
try {
const user = await auth()
console.log(user)
if (!user || !user.user.id) {
return new NextResponse("Unauthorized", { status: 401 })
}
Sun bear
Where do i find this in your repo?
Red-billed TropicbirdOP
it is in the api folder under resumes and checkout
In the multi-form branch
thats my most up-to date branch
Asian black bear
@Red-billed Tropicbird Please stop creating multiple threads for the same issue and focus your conversation in a single thread relevant to your current issue.
Red-billed TropicbirdOP
k mb
Sun bear
From what I see your auth function is returning the user from a session. So it does not really have to do with your prisma schema.
When you console log the user after awaiting auth() you can see what you get from that function.
If there is no user id I would check again the auth.ts in your root because most likely there the auth() does not return what you expect it to return
When you console log the user after awaiting auth() you can see what you get from that function.
If there is no user id I would check again the auth.ts in your root because most likely there the auth() does not return what you expect it to return
Red-billed TropicbirdOP
ok i will try
Red-billed TropicbirdOP
I believe it is due to my adapter erroing in the auth.ts
But I cannot figure out why