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

Add files via upload #71

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions api/config/passport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// we import passport packages required for authentication
import PassportLocal from 'passport-local';
import passport from 'passport';

import { getRepository } from 'typeorm';
import User from '../entities/user';

const init = () => {
// Telling passport we want to use a Local Strategy. In other words,
// we want login with a username/email and password
passport.use(new PassportLocal.Strategy(
// Our user will sign in using an email, rather than a "username"
{
usernameField: 'email',
},
(email, password, done) => {
const repo = getRepository(User);
return repo.findOneOrFail({ where: { email } }).then(
(dbUser) => {
if (dbUser.password !== password) {
return done(null, false, {
message: 'Incorrect password.',
});
}
// If none of the above, return the user
return done(null, dbUser);
},
() => done(null, false, { message: 'no user found' }),
);
},
));
//
// In order to help keep authentication state across HTTP requests,
// Sequelize needs to serialize and deserialize the user
// Just consider this part boilerplate needed to make it all work
passport.serializeUser((user, done) => {
done(null, user.id);
});
//
passport.deserializeUser((id, done) => getRepository(User).findOneOrFail(id).then(
(foundUser) => {
done(null, foundUser);
},
));
};
//
// Exporting our configured passport
export default init;
5 changes: 5 additions & 0 deletions api/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"experimentalDecorators": true
}
}
8 changes: 8 additions & 0 deletions api/middleware/isAuthenticated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const authenticated = (req, res, next) => {
if (!req.isAuthenticated()) {
return res.status(401).send('You are not authenticated');
}
return next();
};

export default authenticated;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading