Skip to content

Commit

Permalink
Configurable Redirect URL (#190)
Browse files Browse the repository at this point in the history
* add callback url config param

* changeset
  • Loading branch information
BurntVal authored Jun 25, 2024
1 parent 7556cda commit bcc35c9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/eleven-ladybugs-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@burnt-labs/abstraxion-core": minor
"@burnt-labs/abstraxion": minor
---

Introduce configurable redirect url param
6 changes: 5 additions & 1 deletion packages/abstraxion-core/src/AbstraxionAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class AbstraxionAuth {
grantContracts?: ContractGrantDescription[];
stake?: boolean;
bank?: SpendLimit[];
callbackUrl?: string;

// Signer
private client?: GranteeSignerClient;
Expand All @@ -36,19 +37,22 @@ export class AbstraxionAuth {
* @param {ContractGrantDescription[]} [grantContracts] - Contracts for granting permissions.
* @param {boolean} [stake] - Indicates whether staking is enabled.
* @param {SpendLimit[]} [bank] - The spend limits for the user.
* @param {string} callbackUrl - preferred callback url to override default
*/
configureAbstraxionInstance(
rpc: string,
restUrl?: string,
grantContracts?: ContractGrantDescription[],
stake?: boolean,
bank?: SpendLimit[],
callbackUrl?: string,
) {
this.rpcUrl = rpc;
this.restUrl = restUrl;
this.grantContracts = grantContracts;
this.stake = stake;
this.bank = bank;
this.callbackUrl = callbackUrl;
}

/**
Expand Down Expand Up @@ -235,7 +239,7 @@ export class AbstraxionAuth {
userAddress: string,
): void {
if (typeof window !== "undefined") {
const currentUrl = window.location.href;
const currentUrl = this.callbackUrl || window.location.href;
const urlParams = new URLSearchParams();

if (this.bank) {
Expand Down
2 changes: 2 additions & 0 deletions packages/abstraxion/src/components/Abstraxion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface AbstraxionConfig {
restUrl?: string;
stake?: boolean;
bank?: SpendLimit[];
callbackUrl?: string;
}

export function AbstraxionProvider({
Expand All @@ -81,6 +82,7 @@ export function AbstraxionProvider({
restUrl={config.restUrl}
stake={config.stake}
bank={config.bank}
callbackUrl={config.callbackUrl}
>
{children}
</AbstraxionContextProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function AbstraxionContextProvider({
restUrl = testnetChainInfo.rest,
stake = false,
bank,
callbackUrl,
}: {
children: ReactNode;
contracts?: ContractGrantDescription[];
Expand All @@ -55,6 +56,7 @@ export function AbstraxionContextProvider({
restUrl?: string;
stake?: boolean;
bank?: SpendLimit[];
callbackUrl?: string;
}): JSX.Element {
const [abstraxionError, setAbstraxionError] = useState("");
const [isConnected, setIsConnected] = useState(false);
Expand All @@ -74,8 +76,9 @@ export function AbstraxionContextProvider({
contracts,
stake,
bank,
callbackUrl,
);
}, [rpcUrl, restUrl, contracts, stake, bank]);
}, [rpcUrl, restUrl, contracts, stake, bank, callbackUrl]);

useEffect(() => {
const searchParams = new URLSearchParams(window.location.search);
Expand Down

0 comments on commit bcc35c9

Please sign in to comment.