MCPcopy Create free account
hub / github.com/async-labs/async / checkUser

Function checkUser

api/server/passwordless.ts:89–119  ·  view source on GitHub ↗
(req: any, res, next)

Source from the content-addressed store, hash-verified

87
88 // middleware for /auth/send-token
89 async function checkUser(req: any, res, next) {
90 // logger.info('passwordless middleware: ' + req.body.user);
91
92 // teamId is only truthy for invitation event
93 // const teamId = req.get('x-async-teamId');
94
95 const { isLoginEvent, user } = req.body;
96
97 // if login or signup event, check if user exist in database
98 if (isLoginEvent) {
99 const existingUser = await User.findOne({ email: user }).setOptions({ lean: true });
100
101 // if user does not exist, respond with error object
102 if (!existingUser) {
103 // logger.info('You do not have permission to use this Login page.');
104 res.status(201).json({
105 error:
106 'You do not have permission to use this Login page. Only registered and invited users can use this Login page.',
107 });
108 return;
109 }
110
111 // if user exists - then no error, call next and exit function early
112 // functions in JS always return (undefined by default)
113 next();
114 return;
115 }
116
117 // if Registration event, no checks are needed
118 next();
119 }
120
121 server.post(
122 '/auth/send-token',

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected