Skip to content

Commit

Permalink
Ensure handles are treated as case insensitive when signing in (#126)
Browse files Browse the repository at this point in the history
* Ensure handles are treated as case insensitive when signing in

* Trim whitespace

* Also lower case verified handle check
  • Loading branch information
tom-sherman authored Sep 24, 2024
1 parent 19dc7fd commit 63ef760
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
11 changes: 10 additions & 1 deletion packages/frontpage/app/(auth)/login/_lib/action.tsx
Original file line number Diff line number Diff line change
@@ -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.trim();
// 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})`,
Expand Down
2 changes: 1 addition & 1 deletion packages/frontpage/lib/data/atproto/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions packages/frontpage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 63ef760

Please sign in to comment.