Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure handles are treated as case insensitive when signing in #126

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) ||

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to strip whitespace too

are handles case sensitive or just want lowercase?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handles are case insensitive (like domain names) but dids are technical case sensitive.

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 @@ -14,6 +14,7 @@
},
"dependencies": {
"@atproto/oauth-types": "^0.1.2",
"@atproto/syntax": "^0.3.0",
Copy link
Contributor Author

@tom-sherman tom-sherman Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @atprotoification of our code begins lol.

I'm gonna gradually convert our handling of core protocol things (handles, DIDs, did doc and pds resolution etc.) to the official libraries but definitely still don't wanna use the API clients because they're not really suited to our use case.

"@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.