-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauthentication.ts
More file actions
26 lines (22 loc) · 897 Bytes
/
authentication.ts
File metadata and controls
26 lines (22 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { Express, NextFunction, Request, Response } from 'express';
import { createApp, S3Bucket } from '../src';
import { s3client } from './s3';
/**
* This simple example shows how you can setup a middleware to
* ensure that requests come from a valid authenticated user.
*
* If you're familiar with expressjs you'll realize there is nothing
* Seshat-specific here... it's just an expressjs middleware executed
* before the Seshat router.
*/
export default (expressApp: Express, _seshatRootDir: string) => {
const ensureAuthenticated = (req: Request, res: Response, next: NextFunction) => {
if (req.headers?.authorization !== 'Bearer a-very-special-secret') {
return res.sendStatus(401);
}
next();
};
expressApp.use('/authentication', ensureAuthenticated, createApp({
bucket: new S3Bucket({ s3client, bucket: 'my-s3-bucket', transformers: [] }),
}));
};