Skip to content

Commit

Permalink
fix: check if window matches deployed origin
Browse files Browse the repository at this point in the history
  • Loading branch information
bompo committed Nov 5, 2024
1 parent 6023cd3 commit 1a8acd9
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/NovaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,17 @@ export class NovaClient {
})
}

private isDeployedOnInstance(): boolean {
return (
typeof window !== "undefined" &&
window.location.origin.includes("wandelbots.io")
)
}

private getInitialHeaders(config: NovaClientConfig): Record<string, string> {
const headers: Record<string, string> = {}
if (
typeof window !== "undefined" &&
!config.instanceUrl &&
config.instanceUrl === window.location.origin
) {
return headers // No authorization needed if deployed on the same instance
if (this.isDeployedOnInstance()) {
return headers
}
if (config.accessToken) {
headers.Authorization = `Bearer ${config.accessToken}`
Expand All @@ -114,14 +117,8 @@ export class NovaClient {
}

private async fetchTokenIfNeeded(): Promise<string | null> {
console.log("Fetching token...")
console.log("Config:", this.config)
if (
typeof window !== "undefined" &&
!this.config.instanceUrl &&
this.config.instanceUrl === window.location.origin
) {
return null // No token needed if deployed on the same instance
if (this.isDeployedOnInstance()) {
return null
}
if (this.config.accessToken) {
return this.config.accessToken
Expand Down

0 comments on commit 1a8acd9

Please sign in to comment.