From 9281dddb6fdd938d35cd92a9167d1d3465faec93 Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Mon, 23 Sep 2024 21:14:12 +0100 Subject: [PATCH 1/3] Ensure handles are treated as case insensitive when signing in --- packages/frontpage/app/(auth)/login/_lib/action.tsx | 11 ++++++++++- packages/frontpage/package.json | 1 + pnpm-lock.yaml | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/frontpage/app/(auth)/login/_lib/action.tsx b/packages/frontpage/app/(auth)/login/_lib/action.tsx index 8237f6c4..afd909b5 100644 --- a/packages/frontpage/app/(auth)/login/_lib/action.tsx +++ b/packages/frontpage/app/(auth)/login/_lib/action.tsx @@ -1,9 +1,18 @@ "use server"; import { signIn } from "@/lib/auth-sign-in"; +import { isValidHandle } from "@atproto/syntax"; export async function loginAction(_prevStart: unknown, formData: FormData) { const identifier = formData.get("identifier") as string; - const result = await signIn(identifier.replace(/^@/, "")); + let handleOrDid = identifier; + // Sanitize only handles + if ( + isValidHandle(identifier) || + isValidHandle(identifier.replace(/^@/, "")) + ) { + handleOrDid = identifier.replace(/^@/, "").toLowerCase(); + } + const result = await signIn(handleOrDid); if (result && "error" in result) { return { error: `An error occured while signing in (${result.error})`, diff --git a/packages/frontpage/package.json b/packages/frontpage/package.json index b3f1c8e2..4321c89f 100644 --- a/packages/frontpage/package.json +++ b/packages/frontpage/package.json @@ -14,6 +14,7 @@ }, "dependencies": { "@atproto/oauth-types": "^0.1.2", + "@atproto/syntax": "^0.3.0", "@libsql/client": "^0.9.0", "@next/env": "^14.2.4", "@radix-ui/react-alert-dialog": "^1.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 633f3388..cb0c04a7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -114,6 +114,9 @@ importers: '@atproto/oauth-types': specifier: ^0.1.2 version: 0.1.2 + '@atproto/syntax': + specifier: ^0.3.0 + version: 0.3.0 '@libsql/client': specifier: ^0.9.0 version: 0.9.0(bufferutil@4.0.8)(utf-8-validate@6.0.3) From 35c4c98dcae7f9a2557cd772c0f6998a2ff2fb8e Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Tue, 24 Sep 2024 11:51:10 +0100 Subject: [PATCH 2/3] Trim whitespace --- packages/frontpage/app/(auth)/login/_lib/action.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontpage/app/(auth)/login/_lib/action.tsx b/packages/frontpage/app/(auth)/login/_lib/action.tsx index afd909b5..ff0a4335 100644 --- a/packages/frontpage/app/(auth)/login/_lib/action.tsx +++ b/packages/frontpage/app/(auth)/login/_lib/action.tsx @@ -4,7 +4,7 @@ import { isValidHandle } from "@atproto/syntax"; export async function loginAction(_prevStart: unknown, formData: FormData) { const identifier = formData.get("identifier") as string; - let handleOrDid = identifier; + let handleOrDid = identifier.trim(); // Sanitize only handles if ( isValidHandle(identifier) || From 53b1d92dd0a1ceba1181cd4183beccb8cf2b6508 Mon Sep 17 00:00:00 2001 From: Tom Sherman Date: Tue, 24 Sep 2024 11:58:12 +0100 Subject: [PATCH 3/3] Also lower case verified handle check --- packages/frontpage/lib/data/atproto/identity.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontpage/lib/data/atproto/identity.ts b/packages/frontpage/lib/data/atproto/identity.ts index 45801eda..36256936 100644 --- a/packages/frontpage/lib/data/atproto/identity.ts +++ b/packages/frontpage/lib/data/atproto/identity.ts @@ -29,7 +29,7 @@ export const getVerifiedDid = cache(async (handle: string) => { if (!plcHandle) return null; - return plcHandle === handle ? did : null; + return plcHandle.toLowerCase() === handle.toLowerCase() ? did : null; }); const DnsQueryResponse = z.object({