fedeya / next-auth-sanity

NextAuth Adapter and Provider for Sanity
https://sanity.io/plugins/next-auth-sanity
MIT License
76 stars 21 forks source link

Error: Unable to parse value of "$email=undefined". Please quote string values #35

Open Jaydeep189 opened 1 year ago

Jaydeep189 commented 1 year ago

I am using credential login with my next.js project with sanity

I have copied the schema from the documentation

my pages/api/sanity/signUp.ts code

import { signUpHandler } from 'next-auth-sanity';

import { createClient } from '@sanity/client';

const client = createClient({
    projectId: process.env.NEXT_PUBLIC_PROJECT_ID,
    dataset: process.env.NEXT_PUBLIC_DATASET || 'production',
    useCdn: true, // set to `false` to bypass the edge cache
    apiVersion: '2023-05-03', // use current date (YYYY-MM-DD) to target the latest API version
    token: process.env.NEXT_PUBLIC_SANITY_API_TOKEN, // or leave blank for unauthenticated usage
});

export default signUpHandler(client);

my signup.tsx code

import { signUp } from 'next-auth-sanity/client';

let email = "sjaydeep189@gmail.com"
let password = "wanted7575"
let name = "jaydeep"
const user = await signUp({
        email,
        password,
        name,     
});

// rest of the code

I was getting this error

Error: Unable to parse value of "$email=undefined". Please quote string values

So I hardcoded the vales inside my code but the error persists. I don't know what I am doing wrong at this point.

fedeya commented 1 year ago

Hi @Jaydeep189 you are using the edge runtime?

Jaydeep189 commented 1 year ago

I am running this locally, via api route provided in nextjs.

I guess it uses edge runtime but I am not sure.

fedeya commented 1 year ago

@Jaydeep189 i released a new version (1.5.0) with it the signUpHandler can be used on the edge and with the new route handlers (app dir), can you try again with the new version?.

I think this may be related because in the edge there is no req.body

If it doesn't work, can you create a repo to reproduce the bug? because i tried again and everything works fine.

Jaydeep189 commented 1 year ago

I am using Nextjs (12.2.5) version which does not include the app dir, I have reproduced the error in a new repository that I am sharing with you

https://github.com/Jaydeep189/next-auth-sanity-example

fedeya commented 1 year ago

Ok this is very strange, I cloned the repo, added the environment variables and started the development server and all works fine. I also tried with Next.js 12.2.5 and it works as well.

image
Jaydeep189 commented 1 year ago

Oh, I didn't check it with postman as a stand alone post request, it works completely fine there, but when I am using this

import { signUp } from 'next-auth-sanity/client';

const user = await signUp({
        email,
        password,
        name,     
});

it gives the error again.

I changed the code to this, and now it is working

fetch("/api/sanity/signUp", {
        body: JSON.stringify({
            name: Data.name,
            password: Data.password,
            email: Data.email
        }),
        headers: {
            "Content-type": "application/json; charset=UTF-8"
        }
    }).then(response => response.json()).then(json => console.log(json));
fedeya commented 1 year ago

the unique difference between your own fetch request and the one made by signUp is the charset in the Content-Type. I added it in the latest version, can you check again?

dhatGuy commented 1 year ago

Getting the same error. The sign-up was working fine before and suddenly started facing this error.

anthlasserre commented 2 months ago

@dhatGuy @Jaydeep189 Can you, guys, double-check that you haven't exported the signUpHandler under the pages folder ? I made this mistake by following the example-app here. Feel free to check the PR above.

https://github.com/fedeya/next-auth-sanity/pull/71