diff --git a/packages/appview/src/api/oauth.ts b/packages/appview/src/api/oauth.ts index 32bbad1..5e3571e 100644 --- a/packages/appview/src/api/oauth.ts +++ b/packages/appview/src/api/oauth.ts @@ -51,7 +51,10 @@ export const createRouter = (ctx: AppContext) => { router.post('/oauth/initiate', async (req, res) => { // Validate const handle = req.body?.handle - if (typeof handle !== 'string' || !isValidHandle(handle)) { + if ( + typeof handle !== 'string' || + !(isValidHandle(handle) || isValidUrl(handle)) + ) { res.status(400).json({ error: 'Invalid handle' }) return } @@ -81,3 +84,17 @@ export const createRouter = (ctx: AppContext) => { return router } + +function isValidUrl(url: string): boolean { + try { + const urlp = new URL(url) + // http or https, no query params or path + return ( + (urlp.protocol === 'http:' || urlp.protocol === 'https:') && + !urlp.search && + !urlp.pathname + ) + } catch (error) { + return false + } +} diff --git a/packages/client/src/pages/LoginPage.tsx b/packages/client/src/pages/LoginPage.tsx index 2974dc7..f3ccd96 100644 --- a/packages/client/src/pages/LoginPage.tsx +++ b/packages/client/src/pages/LoginPage.tsx @@ -63,7 +63,7 @@ const LoginPage = () => { htmlFor="handle" className="block mb-2 text-gray-700 dark:text-gray-300" > - Enter your Bluesky handle: + Enter your Bluesky handle or ATProto PDS: