-
Notifications
You must be signed in to change notification settings - Fork 396
/
shows.ts
30 lines (26 loc) · 902 Bytes
/
shows.ts
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
import { withApiAuthRequired, getAccessToken } from '@auth0/nextjs-auth0';
export default withApiAuthRequired(async function shows(req, res) {
try {
const { accessToken } = await getAccessToken(req, res, {
scopes: ['read:shows']
});
const baseURL =
process.env.AUTH0_BASE_URL?.indexOf('http') === 0
? process.env.AUTH0_BASE_URL
: `https://${process.env.AUTH0_BASE_URL}`;
// This is a contrived example, normally your external API would exist on another domain.
const response = await fetch(baseURL + '/api/my/shows', {
headers: {
Authorization: `Bearer ${accessToken}`
}
});
const shows = await response.json();
res.status(response.status || 200).json(shows);
} catch (error) {
console.error(error);
res.status(error.status || 500).json({
code: error.code,
error: error.message
});
}
});