Skip to content

Commit

Permalink
fix(alchemy-signer): allow for org id to be passed with bundle (#501)
Browse files Browse the repository at this point in the history
* fix(alchemy-signer): allow for org id to be passed with bundle

* feat(alchemy-signer): allow passing custom redirect params
  • Loading branch information
moldy530 authored Mar 11, 2024
1 parent f99e860 commit 8c06f4f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/alchemy/src/signer/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class AlchemySignerClient {
email,
targetPublicKey: publicKey,
expirationSeconds,
redirectParams: params.redirectParams?.toString(),
});

return response;
Expand Down Expand Up @@ -117,6 +118,7 @@ export class AlchemySignerClient {
email,
targetPublicKey: publicKey,
expirationSeconds,
redirectParams: params.redirectParams?.toString(),
});
};

Expand Down
6 changes: 4 additions & 2 deletions packages/alchemy/src/signer/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type CreateAccountParams =
type: "email";
email: string;
expirationSeconds?: number;
redirectParams?: URLSearchParams;
}
| {
type: "passkey";
Expand All @@ -29,6 +30,7 @@ export type EmailAuthParams = {
email: string;
expirationSeconds?: number;
targetPublicKey: string;
redirectParams?: URLSearchParams;
};

export type SignerRoutes = SignerEndpoints[number]["Route"];
Expand All @@ -45,7 +47,7 @@ export type SignerEndpoints = [
{
Route: "/v1/signup";
Body:
| EmailAuthParams
| (Omit<EmailAuthParams, "redirectParams"> & { redirectParams?: string })
| {
passkey: {
challenge: string;
Expand All @@ -67,7 +69,7 @@ export type SignerEndpoints = [
},
{
Route: "/v1/auth";
Body: EmailAuthParams;
Body: Omit<EmailAuthParams, "redirectParams"> & { redirectParams?: string };
Response: {
orgId: string;
};
Expand Down
11 changes: 8 additions & 3 deletions packages/alchemy/src/signer/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import {
} from "./session/manager.js";

export type AuthParams =
| { type: "email"; email: string }
| { type: "email"; bundle: string }
| { type: "email"; email: string; redirectParams?: URLSearchParams }
| { type: "email"; bundle: string; orgId?: string }
| {
type: "passkey";
createNew: false;
Expand Down Expand Up @@ -196,11 +196,13 @@ export class AlchemySigner
? await this.inner.initEmailAuth({
email: params.email,
expirationSeconds: this.sessionManager.expirationTimeMs,
redirectParams: params.redirectParams,
})
: await this.inner.createAccount({
type: "email",
email: params.email,
expirationSeconds: this.sessionManager.expirationTimeMs,
redirectParams: params.redirectParams,
});

this.sessionManager.setTemporarySession({ orgId });
Expand All @@ -214,7 +216,10 @@ export class AlchemySigner
});
});
} else {
const temporarySession = this.sessionManager.getTemporarySession();
const temporarySession = params.orgId
? { orgId: params.orgId }
: this.sessionManager.getTemporarySession();

if (!temporarySession) {
throw new Error("Could not find email auth init session!");
}
Expand Down

0 comments on commit 8c06f4f

Please sign in to comment.