diff --git a/packages/access-api/src/index.js b/packages/access-api/src/index.js index b67819f83..46f318360 100644 --- a/packages/access-api/src/index.js +++ b/packages/access-api/src/index.js @@ -4,7 +4,7 @@ import { notFound } from '@web3-storage/worker-utils/response' import { Router } from '@web3-storage/worker-utils/router' import { postRaw } from './routes/raw.js' import { postRoot } from './routes/root.js' -import { validateEmail } from './routes/validate-email.js' +import { preValidateEmail, validateEmail } from './routes/validate-email.js' import { validateWS } from './routes/validate-ws.js' import { version } from './routes/version.js' import { getContext } from './utils/context.js' @@ -14,7 +14,8 @@ const r = new Router({ onNotFound: notFound }) r.add('options', '*', preflight) r.add('get', '/version', version) -r.add('get', '/validate-email', validateEmail) +r.add('get', '/validate-email', preValidateEmail) +r.add('post', '/validate-email', validateEmail) r.add('get', '/validate-ws', validateWS) r.add('post', '/', postRoot) r.add('post', '/raw', postRaw) diff --git a/packages/access-api/src/routes/validate-email.js b/packages/access-api/src/routes/validate-email.js index 3da06bce7..bb91b696f 100644 --- a/packages/access-api/src/routes/validate-email.js +++ b/packages/access-api/src/routes/validate-email.js @@ -6,8 +6,23 @@ import { HtmlResponse, ValidateEmail, ValidateEmailError, + PendingValidateEmail, } from '../utils/html.js' +/** + * @param {import('@web3-storage/worker-utils/router').ParsedRequest} req + * @param {import('../bindings.js').RouteContext} env + */ +export async function preValidateEmail(req, env) { + if (!req.query?.ucan) { + return new HtmlResponse( + + ) + } + + return new HtmlResponse() +} + /** * @param {import('@web3-storage/worker-utils/router').ParsedRequest} req * @param {import('../bindings.js').RouteContext} env diff --git a/packages/access-api/src/utils/html.js b/packages/access-api/src/utils/html.js index 9db97041b..56814b4b8 100644 --- a/packages/access-api/src/utils/html.js +++ b/packages/access-api/src/utils/html.js @@ -95,6 +95,40 @@ export class HtmlResponse extends Response { } } +/** + * + * @param {object} props + * @param {boolean} [props.autoApprove] + */ +export const PendingValidateEmail = ({ autoApprove }) => ( +
+ +
+

Validating Email

+
+ +
+ {autoApprove ? ( +