forked from cerc-io/snowballtools-base
nabarun
bc52b34462
Part of [Service provider auctions for web deployments](https://www.notion.so/Service-provider-auctions-for-web-deployments-104a6b22d47280dbad51d28aa3a91d75) - Remove LIT authentication Co-authored-by: Neeraj <neeraj.rtly@gmail.com> Reviewed-on: cerc-io/snowballtools-base#4
29 lines
759 B
TypeScript
29 lines
759 B
TypeScript
import { BASE_URL } from './constants';
|
|
|
|
export async function verifyAccessCode(
|
|
accesscode: string,
|
|
): Promise<boolean | null> {
|
|
const res = await fetch(`${BASE_URL}/auth/accesscode`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
accesscode,
|
|
}),
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
credentials: 'include',
|
|
});
|
|
// If API returns a non-empty 200, this is a valid access code.
|
|
if (res.status == 200) {
|
|
const isValid = (await res.json()).isValid as boolean;
|
|
console.log('isValid', isValid);
|
|
return isValid;
|
|
} else if (res.status === 204) {
|
|
return null;
|
|
} else {
|
|
throw new Error(
|
|
`Unexpected response from access code endpoint: ${res.status}: ${await res.text()}`,
|
|
);
|
|
}
|
|
}
|