Skip to content

Commit

Permalink
feat: allow override iframe url from param
Browse files Browse the repository at this point in the history
  • Loading branch information
gllm-dev committed Mar 19, 2024
1 parent 60ae0bc commit 67a0356
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfort/openfort-js",
"version": "0.5.19",
"version": "0.5.20",
"description": "",
"author": "Openfort",
"repository": {
Expand Down
4 changes: 1 addition & 3 deletions src/clients/iframe-client.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
export class IframeClient {
private readonly _iframe: HTMLIFrameElement;

constructor(publishableKey: string, accessToken: string) {
constructor(publishableKey: string, accessToken: string, baseURL = "https://iframe.openfort.xyz") {
if (!document) {
throw new Error("must be run in a browser");
}

const baseURL = process.env.IFRAME_URL || process.env.NEXT_PUBLIC_IFRAME_URL || "https://iframe.openfort.xyz";

const actualIframeURL = document.getElementById("openfort-iframe") as HTMLIFrameElement;
if (actualIframeURL) {
actualIframeURL.src = baseURL + "/iframe?accessToken=" + accessToken + "&publishableKey=" + publishableKey;
Expand Down
8 changes: 5 additions & 3 deletions src/openfort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import {SessionStorage} from "./storage/sessionStorage";
export default class Openfort {
private _signer?: ISigner;
private _publishableKey: string;
private readonly _iframeURL: string;
private readonly _instanceManager: InstanceManager;

constructor(publishableKey: string = null) {
constructor(publishableKey: string = null, iframeURL = "https://iframe.openfort.xyz") {
this._instanceManager = new InstanceManager(new SessionStorage(), new LocalStorage(), new LocalStorage());
this._iframeURL = iframeURL;
this._publishableKey = publishableKey;
}

Expand All @@ -47,7 +49,7 @@ export default class Openfort {
const signerType = this._instanceManager.getSignerType();
if (signerType === SignerType.EMBEDDED) {
this.recoverPublishableKey();
const signer = new EmbeddedSigner(this._publishableKey, this._instanceManager);
const signer = new EmbeddedSigner(this._publishableKey, this._instanceManager, this._iframeURL);
await signer.logout();
this._instanceManager.removeSignerType();
return;
Expand Down Expand Up @@ -113,7 +115,7 @@ export default class Openfort {
}

this.recoverPublishableKey();
return new EmbeddedSigner(this._publishableKey, this._instanceManager);
return new EmbeddedSigner(this._publishableKey, this._instanceManager, this._iframeURL);
}

public async configureEmbeddedSignerRecovery(recovery: IRecovery, chainId: number): Promise<void> {
Expand Down
5 changes: 4 additions & 1 deletion src/signer/embedded.signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ export class EmbeddedSigner implements ISigner {
private readonly _publishableKey: string;
private readonly _instanceManager: InstanceManager;
private _recovery: IRecovery;
private readonly _baseURL;

constructor(publishableKey: string, instanceManager: InstanceManager) {
constructor(publishableKey: string, instanceManager: InstanceManager, baseURL = "https://iframe.openfort.xyz") {
this._instanceManager = instanceManager;
this._publishableKey = publishableKey;
this._baseURL = baseURL;
this.configureIframeClient();
}

Expand All @@ -31,6 +33,7 @@ export class EmbeddedSigner implements ISigner {
this._iframeClient = new IframeClient(
this._publishableKey,
this._instanceManager.getAccessToken(),
this._baseURL,
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const VERSION = "0.5.19";
export const VERSION = "0.5.20";
export const PACKAGE = "@openfort/openfort-js";

0 comments on commit 67a0356

Please sign in to comment.