-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathmiddleware.ts
More file actions
34 lines (31 loc) · 1.05 KB
/
middleware.ts
File metadata and controls
34 lines (31 loc) · 1.05 KB
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
27
28
29
30
31
32
33
34
/*
* This file is a mod of src/auth/middleware.ts and is used when starting the server via `yarn serve-dev`
* It bypasses the authentication for local development
*/
import muuid, { MUUID } from 'uuid-mongodb'
import { AuthUserType } from '../../types.js'
import { logger } from '../../logger.js'
import type { ApolloServerPlugin } from 'apollo-server-plugin-base'
export const localDevBypassAuthContext = (() => {
const testUUID: MUUID = muuid.v4()
return async ({ req }): Promise<any> => {
const user: AuthUserType = {
roles: ['user_admin', 'org_admin', 'editor'],
uuid: testUUID,
isBuilder: false
}
logger.info(`The user.roles for this session is: ${user.roles.toString()}`)
return { user }
}
})()
export const loggerPlugin: ApolloServerPlugin = {
async requestDidStart (ctx) {
const startTime = process.uptime()
return {
async willSendResponse () {
ctx.logger.info(ctx.request.query)
ctx.logger.info(`query resolved in ${((process.uptime() - startTime) * 1000).toFixed(4)}ms`)
}
}
}
}