@arkadecx/arkade-cloud-functions-auth
v1.5.0-alpha-8
Published
Cloud functions Auth
Downloads
130
Keywords
Readme
arkade-cloud-functions-auth
Install
yarn install @arkadecx/arkade-cloud-functions-auth
Usage
Server side
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' });
}
AuthOptions
| 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 | [] |
Client side
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),
});
Limitation
- Only work with NextJS api at the moment
- If POST request, only works with Content-Type: application/json