1
0
mirror of https://github.com/microsoft/TypeScript-Node-Starter.git synced 2026-03-24 02:43:03 +00:00

Migrate TSLint to ESLint. Closes #209

This commit rewrites linting support in the project to be based solely
on the ESLint as advised by the TSLint tool authors:
https://medium.com/palantir/tslint-in-2019-1a144c2317a9

The migration is based on default, recommended settings for TypeScript
in ESLint and is expected to be updated in future to better fit project
goals.

All references has been updated and replaced with relevant ESLint
context:

- dependencies migration from TSLint to ESLint
- VSCode configuration changes to support ESLint exension
- VSCode extensions recommendation changes
- `.eslintrc` and `.eslintignore` configuration files added
- all error level problems in the source files are covered by this
  migration

Thanks!
This commit is contained in:
Peter Blazejewicz
2019-07-14 22:45:19 +02:00
parent f90451ac0e
commit 3414ceca45
22 changed files with 1076 additions and 660 deletions

View File

@@ -11,13 +11,13 @@ const LocalStrategy = passportLocal.Strategy;
const FacebookStrategy = passportFacebook.Strategy;
passport.serializeUser<any, any>((user, done) => {
done(undefined, user.id);
done(undefined, user.id);
});
passport.deserializeUser((id, done) => {
User.findById(id, (err, user) => {
done(err, user);
});
User.findById(id, (err, user) => {
done(err, user);
});
});
@@ -25,19 +25,19 @@ passport.deserializeUser((id, done) => {
* Sign in using Email and Password.
*/
passport.use(new LocalStrategy({ usernameField: "email" }, (email, password, done) => {
User.findOne({ email: email.toLowerCase() }, (err, user: any) => {
if (err) { return done(err); }
if (!user) {
return done(undefined, false, { message: `Email ${email} not found.` });
}
user.comparePassword(password, (err: Error, isMatch: boolean) => {
if (err) { return done(err); }
if (isMatch) {
return done(undefined, user);
}
return done(undefined, false, { message: "Invalid email or password." });
User.findOne({ email: email.toLowerCase() }, (err, user: any) => {
if (err) { return done(err); }
if (!user) {
return done(undefined, false, { message: `Email ${email} not found.` });
}
user.comparePassword(password, (err: Error, isMatch: boolean) => {
if (err) { return done(err); }
if (isMatch) {
return done(undefined, user);
}
return done(undefined, false, { message: "Invalid email or password." });
});
});
});
}));
@@ -61,81 +61,81 @@ passport.use(new LocalStrategy({ usernameField: "email" }, (email, password, don
* Sign in with Facebook.
*/
passport.use(new FacebookStrategy({
clientID: process.env.FACEBOOK_ID,
clientSecret: process.env.FACEBOOK_SECRET,
callbackURL: "/auth/facebook/callback",
profileFields: ["name", "email", "link", "locale", "timezone"],
passReqToCallback: true
clientID: process.env.FACEBOOK_ID,
clientSecret: process.env.FACEBOOK_SECRET,
callbackURL: "/auth/facebook/callback",
profileFields: ["name", "email", "link", "locale", "timezone"],
passReqToCallback: true
}, (req: any, accessToken, refreshToken, profile, done) => {
if (req.user) {
User.findOne({ facebook: profile.id }, (err, existingUser) => {
if (err) { return done(err); }
if (existingUser) {
req.flash("errors", { msg: "There is already a Facebook account that belongs to you. Sign in with that account or delete it, then link it with your current account." });
done(err);
} else {
User.findById(req.user.id, (err, user: any) => {
if (err) { return done(err); }
user.facebook = profile.id;
user.tokens.push({ kind: "facebook", accessToken });
user.profile.name = user.profile.name || `${profile.name.givenName} ${profile.name.familyName}`;
user.profile.gender = user.profile.gender || profile._json.gender;
user.profile.picture = user.profile.picture || `https://graph.facebook.com/${profile.id}/picture?type=large`;
user.save((err: Error) => {
req.flash("info", { msg: "Facebook account has been linked." });
done(err, user);
});
if (req.user) {
User.findOne({ facebook: profile.id }, (err, existingUser) => {
if (err) { return done(err); }
if (existingUser) {
req.flash("errors", { msg: "There is already a Facebook account that belongs to you. Sign in with that account or delete it, then link it with your current account." });
done(err);
} else {
User.findById(req.user.id, (err, user: any) => {
if (err) { return done(err); }
user.facebook = profile.id;
user.tokens.push({ kind: "facebook", accessToken });
user.profile.name = user.profile.name || `${profile.name.givenName} ${profile.name.familyName}`;
user.profile.gender = user.profile.gender || profile._json.gender;
user.profile.picture = user.profile.picture || `https://graph.facebook.com/${profile.id}/picture?type=large`;
user.save((err: Error) => {
req.flash("info", { msg: "Facebook account has been linked." });
done(err, user);
});
});
}
});
}
});
} else {
User.findOne({ facebook: profile.id }, (err, existingUser) => {
if (err) { return done(err); }
if (existingUser) {
return done(undefined, existingUser);
}
User.findOne({ email: profile._json.email }, (err, existingEmailUser) => {
if (err) { return done(err); }
if (existingEmailUser) {
req.flash("errors", { msg: "There is already an account using this email address. Sign in to that account and link it with Facebook manually from Account Settings." });
done(err);
} else {
const user: any = new User();
user.email = profile._json.email;
user.facebook = profile.id;
user.tokens.push({ kind: "facebook", accessToken });
user.profile.name = `${profile.name.givenName} ${profile.name.familyName}`;
user.profile.gender = profile._json.gender;
user.profile.picture = `https://graph.facebook.com/${profile.id}/picture?type=large`;
user.profile.location = (profile._json.location) ? profile._json.location.name : "";
user.save((err: Error) => {
done(err, user);
});
}
});
});
}
} else {
User.findOne({ facebook: profile.id }, (err, existingUser) => {
if (err) { return done(err); }
if (existingUser) {
return done(undefined, existingUser);
}
User.findOne({ email: profile._json.email }, (err, existingEmailUser) => {
if (err) { return done(err); }
if (existingEmailUser) {
req.flash("errors", { msg: "There is already an account using this email address. Sign in to that account and link it with Facebook manually from Account Settings." });
done(err);
} else {
const user: any = new User();
user.email = profile._json.email;
user.facebook = profile.id;
user.tokens.push({ kind: "facebook", accessToken });
user.profile.name = `${profile.name.givenName} ${profile.name.familyName}`;
user.profile.gender = profile._json.gender;
user.profile.picture = `https://graph.facebook.com/${profile.id}/picture?type=large`;
user.profile.location = (profile._json.location) ? profile._json.location.name : "";
user.save((err: Error) => {
done(err, user);
});
}
});
});
}
}));
/**
* Login Required middleware.
*/
export const isAuthenticated = (req: Request, res: Response, next: NextFunction) => {
if (req.isAuthenticated()) {
return next();
}
res.redirect("/login");
if (req.isAuthenticated()) {
return next();
}
res.redirect("/login");
};
/**
* Authorization Required middleware.
*/
export const isAuthorized = (req: Request, res: Response, next: NextFunction) => {
const provider = req.path.split("/").slice(-1)[0];
const provider = req.path.split("/").slice(-1)[0];
if (_.find(req.user.tokens, { kind: provider })) {
next();
} else {
res.redirect(`/auth/${provider}`);
}
if (_.find(req.user.tokens, { kind: provider })) {
next();
} else {
res.redirect(`/auth/${provider}`);
}
};