Skip to content

Commit

Permalink
fix: did at protocol regex - fix #150 (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
pagoru authored Oct 27, 2024
1 parent 581811a commit b556897
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { FormEvent, useCallback } from "react";
import { Account } from "shared/types";
import { useAccount } from "shared/hooks";
import { PROTO_DID_REGEX } from "shared/consts";

type Props = {
account: Account;
Expand All @@ -15,8 +16,7 @@ export const BskyComponent: React.FC<Props> = ({ account }) => {
const data = new FormData(event.target as unknown as HTMLFormElement);
const did = data.get("did") as string;

console.log(did);
if (!did || did.length !== 24) return;
if (!did || !new RegExp(PROTO_DID_REGEX).test(did)) return;

await at.create(did);
}, []);
Expand Down Expand Up @@ -52,17 +52,16 @@ export const BskyComponent: React.FC<Props> = ({ account }) => {
<br />
<br />
<div>
2. Copy the (did) red part only (24 letters/numbers) to the input{" "}
<br />
<label style={{ backgroundColor: "black" }}>did=did:plc:</label>
2. Copy the (did) red part only to the input <br />
<label style={{ backgroundColor: "black" }}>did=</label>
<b
style={{ backgroundColor: "rgba(206, 2, 2, 0.66)", color: "white" }}
>
xxxxxxxxxxxxxxxxxxxxxxxx
did:plc:xxxxxxxxxxxxxxxxxxxxxxxx
</b>
</div>
<br />
<input placeholder="bluesky account did" name="did" maxLength={24} />
<input placeholder="bluesky account did" name="did" />
<br />
<br />
<button type="submit" style={{ cursor: "pointer" }}>
Expand Down
1 change: 1 addition & 0 deletions app/client/src/shared/consts/at.consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const PROTO_DID_REGEX = /^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$/;
1 change: 1 addition & 0 deletions app/client/src/shared/consts/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./urls.consts";
export * from "./captcha.consts";
export * from "./at.consts";

0 comments on commit b556897

Please sign in to comment.