Skip to content

Commit

Permalink
account: pass projectAccessKey and jwtAuth for relayer instantiation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka authored Dec 14, 2024
1 parent cfbad19 commit 578f330
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/account/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ export class Account {
if (isRelayer(found.relayer)) return found.relayer
return new RpcRelayer({
...found.relayer,
// If there's an access key, we don't pass the JWT, because browser-side usage of this code mandates an access key
// and passing a JWT causes a CORS error.
...(this.projectAccessKey ? { projectAccessKey: this.projectAccessKey } : { jwtAuth: this.jwt })
// we pass both projectAccessKey and jwtAuth because the projectAccessKey is
// used either for unauthenticated access, or gas sponsorship even if the jwtAuth is provided,
...({ projectAccessKey: this.projectAccessKey, jwtAuth: this.jwt })
})
}

Expand Down
9 changes: 6 additions & 3 deletions packages/auth/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,9 @@ export class Session {
dump: SessionDumpV1 | SessionDumpV2
editConfigOnMigration: (config: commons.config.Config) => commons.config.Config
onMigration?: (account: Account) => Promise<boolean>
projectAccessKey?: string
}): Promise<Session> {
const { dump, settings, editConfigOnMigration, onMigration, orchestrator } = args
const { dump, settings, editConfigOnMigration, onMigration, orchestrator, projectAccessKey } = args
const { contexts, networks, tracker, services } = { ...SessionSettingsDefault, ...settings }

let account: Account
Expand All @@ -343,7 +344,8 @@ export class Session {
networks,
contexts,
orchestrator,
jwt: jwtExpired ? undefined : dump.jwt?.token
jwt: jwtExpired ? undefined : dump.jwt?.token,
projectAccessKey
})

// TODO: This property may not hold if the user adds a new network
Expand All @@ -370,7 +372,8 @@ export class Session {
networks,
contexts,
orchestrator,
jwt: jwtExpired ? undefined : dump.jwt?.token
jwt: jwtExpired ? undefined : dump.jwt?.token,
projectAccessKey
})
} else {
throw Error('Invalid dump format')
Expand Down

0 comments on commit 578f330

Please sign in to comment.