- I'm currently facing challenges trying to integrate passport, passport-local, and express-session with Typescript.
- After installing all four necessary libraries - @types/passport, @types/express-session @types/passport-local, and @types/express - I intend to utilize connect-redis for storing sessions in the redis database.
At the moment, I'm encountering two errors:
The error 'Property 'emailVerified' does not exist on type 'User'
and
The error 'Property 'id' does not exist on type 'User'
I attempted to create declarations based on responses from various sources like HERE, HERE, and HERE. However, none of these solutions seem to rectify the issue. It would be greatly appreciated if someone could pinpoint where I might be making a mistake.
tsconfig.json
{
"compilerOptions": {
"lib": ["es2020"],
"module": "commonjs",
"moduleResolution": "node",
"target": "es2020",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"noImplicitAny": false,
"outDir": "dist",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"baseUrl": ".",
"paths": {
"server/*": ["src/server/*"],
"tests/*": ["src/tests/*"],
"data/*": ["src/data/*"],
"config": ["src/config"]
},
"typeRoots": ["./src/@types", "./node_modules/@types"]
}
}
src/@types/express/index.d.ts
declare global {
export namespace Express {
export interface User {
id: string;
emailVerified: boolean;
}
}
}
passport.ts
import { Express, Request } from 'express';
import passport from 'passport';
import {
IStrategyOptionsWithRequest,
IVerifyOptions,
Strategy as LocalStrategy,
} from 'passport-local';
import { AuthService } from 'server/services';
import { isHashEqual } from 'server/utils/functions';
const strategyOptions: IStrategyOptionsWithRequest = {
usernameField: 'email',
passwordField: 'password',
passReqToCallback: true,
};
// More passport code ...
and a snippet from the controller file
auth.controller.ts
static async verifyEmail(req: Request, res: Response, next: NextFunction) {
try {
const { accountId, token } = req.params;
// More controller code ...
} catch (error) {
return next(error);
}
}
Illustratively on VSCode, these are the errors I'm encountering, along with a similar issue regarding the emailVerified property.
If anyone could kindly provide guidance on resolving these errors, it would be highly appreciated.