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

account: pass projectAccessKey and jwtAuth for relayer instantiation #629

Merged
merged 2 commits into from
Dec 14, 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
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
Loading