hiteshchoudhary / chai-backend

A video series on chai aur code youtube channel
5.36k stars 802 forks source link

Error in generating refresh and access token #121

Closed Krrishsahu06 closed 6 months ago

Krrishsahu06 commented 6 months ago

when Im sending my email and password the "generateAccessAndRefereshTokens" fn catching error that "Something went wrong while generating access and refresh token" . when I console log the "user" its working but when I consolelog the "refreshToken" the fn goes to catch block I think something is wrong with "generateAccessToken" and "generateRefreshToken" methods defined in user.model file

const generateAccessAndRefereshTokens = async(userId) =>{ try { const user = await User.findById(userId) const accessToken = await user.generateAccessToken() const refreshToken = await user.generateRefreshToken()

    user.refreshToken = refreshToken
    await user.save({ validateBeforeSave: false })

    return {accessToken, refreshToken}

} catch (error) {
    throw new ApiError(500, "Something went wrong while generating referesh and access token")
}

}