yarn install @arkadecx/arkade-cloud-functions-auth
import { auth } from '@arkadecx/arkade-cloud-functions-auth';
const r = auth(req, {
hmacSecret: 'any secret',
originDomainWhitelist: ['www.google.com.au'],
});
if (!r) {
return res.status(401).json({ error: 'Unauthorised' });
}
name |
desc |
default value |
enableHmacCheck |
if enable hmac check |
true |
hmacSecret |
secrect used to encrypt |
'' |
enableOriginCheck |
if enable origin domain check |
true |
originDomainWhitelist |
origin domain whilelist |
[] |
import { hmacSignature } from '@arkadecx/arkade-cloud-functions-auth';
const body = {
//payload here
};
const route = '/api/route';
const now = Date.now();
const signature = hmacSignature(
'any secret',
now,
route,
body
);
const response = await fetch(route, {
method: 'post',
headers: {
'Content-Type': 'application/json',
'x-authentication': `${now}:${signature}`,
},
body: JSON.stringify(body),
});
- Only work with NextJS api at the moment
- If POST request, only works with Content-Type: application/json