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

Showing false errors #238924

Closed
AyushBadola22 opened this issue Jan 28, 2025 · 1 comment
Closed

Showing false errors #238924

AyushBadola22 opened this issue Jan 28, 2025 · 1 comment
Assignees
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)

Comments

@AyushBadola22
Copy link

AyushBadola22 commented Jan 28, 2025

Type: Bug

NOTE : CODE IN THE FILE IS ATTACHED IN THE MARKDOWN AT THE LAST

Hey I am not sure if I need to share my whole project or just this file is enough .
Anyway here is the short explaination ->

This file is the Options file for next js authentication. I am using credentials method.
In my project I have used type any at many places and to follow best practices I wanted to change them.
In the options.ts file the authorize method gives me some error that type of credentials doesn't match even though its matching. I spend a lot of time just to see where it went wrong.

Then chatgpt recommended me to run npm run lint which will show the potential errors.
All the errors in there is not from this file and when I locally ran the code npm run dev , the login functionality is working fine.

Image

But still the authorize function is giving me errors in vs code.

Image

I don't want that in future same thing repeats as I spend my energy only to find out in actual there were no errors.
Note : I already matched the typescript versions of the project and vs code to avoid any conflictions.

`Options.ts` file code - dropdown
import { NextAuthOptions } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import bcrypt from  "bcryptjs";
import dbConnect from "@/lib/dbConnect";
import UserModel, { User } from "@/model/User";

export const authOptions : NextAuthOptions = {
    providers: [
        CredentialsProvider({
            id : "credentials" , 
            name : "Credentials", 
            credentials : {
                identifier : {label : "Email or Username", type : "text"}, 
                password : { label : "Password", type : "password"} , 
            }, 
            async authorize(credentials?: Record<"identifier" | "password", string> | undefined) : Promise<User | null>{
                if(!credentials) return null;
                await dbConnect(); 
                try {
                    const user = await UserModel.findOne({
                        $or : [
                            {email : credentials.identifier}  , 
                            {username : credentials.identifier}
                        ]
                    }); 


                    if(!user){
                        throw new Error("No user found with such username or email"); 
                    }

                    if(!user.isVerified){
                        throw new Error("Please verify your account before login");
                    }

                    const isCorrectPassword = await bcrypt.compare(credentials.password , user.password)

                    if(isCorrectPassword){
                        return user; 
                    }
                    else {
                        throw new Error("Incorrect password")
                    }
                } catch (error) {
                    const typedError = error as Error & {message : string};
                    if(typedError.message){
                        throw new Error(typedError.message)
                    } else throw new Error("An error occured while trying to login");
                }
            } ,
        }) ,
    ], 
    callbacks : {
        async jwt ({token , user }){
            if(user){
                token._id = user._id?.toString(); 
                token.isVerified = user.isVerified;
                token.isAcceptingMessages = (user as User).isAcceptingResponse; 
                token.username = user.username
            }
            return token; 
        }, 
        async session ({session, token}){
            
            if(token) {
                session.user._id = token._id; 
                session.user.isVerified = token.isVerified; 
                session.user.isAcceptingMessages = token.isAcceptingMessages; 
                session.user.username = token.username; 
            }
            return session; 
        }
    }, 
    pages : {
        signIn : "/signin",
    }, 
    session: {
        strategy: 'jwt',
    },
    secret : process.env.NEXTAUTH_SECRET
}

VS Code version: Code 1.96.4 (cd4ee3b, 2025-01-16T00:16:19.038Z)
OS version: Windows_NT x64 10.0.26100
Modes:

System Info
Item Value
CPUs 12th Gen Intel(R) Core(TM) i5-12500H (16 x 3110)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) undefined
Memory (System) 15.69GB (3.78GB free)
Process Argv --crash-reporter-id 5767e645-bcaf-493d-905a-ce91fe543ffb
Screen Reader no
VM 0%
Extensions (32)
Extension Author (truncated) Version
better-comments aar 3.0.2
vscode-custom-css be5 7.4.2
vscode-tailwindcss bra 0.14.1
vscode-animations Bra 2.0.7
simple-react-snippets bur 1.2.8
competitive-programming-helper Div 2025.1.1737478840
bracket-pair-toggler dzh 0.0.3
vscode-great-icons emm 2.1.112
auto-close-tag for 0.5.15
code-runner for 0.12.2
c-cpp-runner fra 9.4.9
copilot Git 1.259.0
copilot-chat Git 0.23.2
python ms- 2024.14.1
vscode-pylance ms- 2024.12.1
jupyter ms- 2024.11.0
jupyter-keymap ms- 1.1.2
jupyter-renderers ms- 1.0.21
vscode-jupyter-cell-tags ms- 0.1.9
vscode-jupyter-slideshow ms- 0.1.6
cpptools ms- 1.22.11
cpptools-extension-pack ms- 1.3.0
prisma Pri 6.2.1
es7-react-js-snippets rod 1.9.3
sonarlint-vscode Son 4.15.0
ayu tea 1.0.5
pdf tom 1.2.2
vscode-lldb vad 1.11.2
vscode-icons vsc 12.10.0
pretty-ts-errors Yoa 0.6.1
markdown-pdf yza 1.5.0
material-theme zhu 3.17.7
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyt551cf:31179979
vscod805cf:30301675
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
2i9eh265:30646982
962ge761:30959799
pythonnoceb:30805159
pythonmypyd1:30879173
h48ei257:31000450
pythontbext0:30879054
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
dvdeprecation:31068756
dwnewjupyter:31046869
newcmakeconfigv2:31071590
nativerepl1:31139838
pythonrstrctxt:31112756
nativeloc1:31192215
cf971741:31144450
iacca1:31171482
notype1:31157159
5fd0e150:31155592
dwcopilot:31170013
stablechunks:31184530
6074i472:31201624
dwoutputs:31217127
9064b325:31222308
copilot_t_ci:31222730

@AyushBadola22 AyushBadola22 reopened this Jan 28, 2025
@mjbvz mjbvz added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label Jan 28, 2025
Copy link

We closed this issue because it is a question about using VS Code rather than an issue or feature request. Please search for help on StackOverflow, where the community has already answered thousands of similar questions. You may find their guide on asking a new question helpful if your question has not already been asked. See also our issue reporting guidelines.

Happy Coding!

@vs-code-engineering vs-code-engineering bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)
Projects
None yet
Development

No branches or pull requests

2 participants