-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGetUser.ts
More file actions
27 lines (23 loc) · 824 Bytes
/
GetUser.ts
File metadata and controls
27 lines (23 loc) · 824 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
27
import express from 'express';
import { withOcUserAuth } from '@ordercloud/catalyst';
import { Me, } from 'ordercloud-javascript-sdk';
import { FullDecodedToken } from '@ordercloud/catalyst/dist/Types/ExtendedToken';
var router = express.Router();
router.get('/api/user',
// verifies the request includes an active OrderCloud bearer token
withOcUserAuth(
getUserHandler,
["Shopper"], // only tokens with Shopper security role may access
["Buyer", "Seller"], // only tokens with user type Buyer may access
)
);
async function getUserHandler(req, res, next) {
var token: FullDecodedToken = req.ocToken;
try {
var user = await Me.Get({ accessToken: token.raw });
res.json(user).status(200);
} catch (err) {
next(err);
}
}
export default router;