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

fix(alchemy-signer): allow for org id to be passed with bundle #501

Merged
merged 2 commits into from
Mar 11, 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
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
Copy link
Contributor

@dphilipson dphilipson Mar 9, 2024

Choose a reason for hiding this comment

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

Does this change mean the org id no longer needs to be kept in storage for new magic links?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yea exactly, but I left it for now to be backwards compatible

? { orgId: params.orgId }
: this.sessionManager.getTemporarySession();

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