chore: Add static current user temporarily
This commit is contained in:
@@ -8,6 +8,7 @@ import logger from './helpers/logger';
|
||||
import morgan from './helpers/morgan';
|
||||
import errorHandler from './helpers/error-handler';
|
||||
import './config/database';
|
||||
import authentication from './helpers/authentication';
|
||||
|
||||
const app = express();
|
||||
const port = appConfig.port;
|
||||
@@ -15,7 +16,8 @@ const port = appConfig.port;
|
||||
app.use(morgan);
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: false }));
|
||||
app.use(cors(corsOptions))
|
||||
app.use(cors(corsOptions));
|
||||
app.use(authentication);
|
||||
app.use('/graphql', graphQLInstance);
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
|
18
packages/backend/src/helpers/authentication.ts
Normal file
18
packages/backend/src/helpers/authentication.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import User from '../models/user';
|
||||
import UserType from '../types/user';
|
||||
|
||||
interface RequestWithCurrentUser extends Request {
|
||||
currentUser: UserType
|
||||
}
|
||||
|
||||
const authentication = async (req: RequestWithCurrentUser, _res: Response, next: NextFunction) => {
|
||||
// We set authentication to use the sample user we created temporarily.
|
||||
req.currentUser = await User.query().findOne({
|
||||
email: 'user@automatisch.com'
|
||||
})
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export default authentication;
|
9
packages/backend/src/types/user.d.ts
vendored
Normal file
9
packages/backend/src/types/user.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
type User = {
|
||||
id: number,
|
||||
email: string,
|
||||
password: string,
|
||||
createdAt: string,
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
export default User;
|
Reference in New Issue
Block a user