Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue while i sign up as a new user #19

Open
Adigup13 opened this issue May 23, 2024 · 1 comment
Open

Issue while i sign up as a new user #19

Adigup13 opened this issue May 23, 2024 · 1 comment

Comments

@Adigup13
Copy link

When I sign up as a new user the browser shows the alert message " Unexpected token '<', "<!DOCTYPE "... is not valid JSON"

@fazilsnippet
Copy link

Generate the tokens inside the user model.
Create two tokens "access and refresh token"
While creating user don't send the password and access token as a response, through cookie.
Like this:-
const newuser = await User.create({
fullName,
Profile-pic: profilePic?url, //use multer and cloudinary for uploading images
coverImage: coverImage?.url || "",
email,
password,
username: username.toLowerCase()
})

const createdUser = await User.findById(user._id).select(
    "-password -refreshToken"
)

if (!createdUser) {
    throw new ApiError(500, "Something went wrong while registering the user")
}

return res.status(201).json(
    new ApiResponse(200, createdUser, "User registered Successfully")
)

And use "async-await and try catch" while working with database.
Use cookieparser in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants