checkHandler = async (req, res) => {
res.header('Access-Control-Allow-Origin', req.headers.origin)
res.header('Access-Control-Allow-Credentials', 'true')
if (req.signedCookies && req.signedCookies.endpointservicesuser) {
const uid = req.signedCookies.endpointservicesuser;
const sa = JSON.parse(req.context.secrets['endpointservices_secretadmin_service_account_key']);
const access_token = await getAccessTokenFromServiceAccount(sa);
await signinWithAccessToken(firebase, access_token)
if (req.headers.origin === "https://endpointservices.static.observableusercontent.com" || await isOwner(uid, subdomain(req.headers.origin))) {
console.log(`Minting ${uid} from ${subdomain(req.headers.origin)}`)
res.send(await createCustomToken(sa, uid));
} else {
res.status(403).end()
}
} else {
res.status(401).end()
}
}