forked from clerk/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetAuth.ts
More file actions
20 lines (17 loc) · 733 Bytes
/
Copy pathgetAuth.ts
File metadata and controls
20 lines (17 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import type { AuthObject } from '@clerk/backend';
import type { Request as ExpressRequest } from 'express';
import { middlewareRequired } from './errors';
import { requestHasAuthObject } from './utils';
/**
* Retrieves the Clerk AuthObject using the current request object.
*
* @param {ExpressRequest} req - The current request object.
* @returns {AuthObject} Object with information about the request state and claims.
* @throws {Error} `clerkMiddleware` or `requireAuth` is required to be set in the middleware chain before this util is used.
*/
export const getAuth = (req: ExpressRequest): AuthObject => {
if (!requestHasAuthObject(req)) {
throw new Error(middlewareRequired('getAuth'));
}
return req.auth;
};