Skip to content

feat: Implement token callback; fix CI testing #439

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

Merged
merged 7 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
change name of callback function
  • Loading branch information
filipecabaco committed Dec 2, 2024
commit 8d6ab76f46bcda851c2cd1a8b70537ba94b3f05c
4 changes: 2 additions & 2 deletions src/RealtimeChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ export default class RealtimeChannel {

this.joinPush
.receive('ok', async ({ postgres_changes }: PostgresChangesFilters) => {
if (this.socket.accessTokenCallback) {
let token = await this.socket.accessTokenCallback()
if (this.socket.accessToken) {
let token = await this.socket.accessToken()
this.socket.setAuth(token)
} else {
this.socket.accessToken &&
Expand Down
10 changes: 5 additions & 5 deletions src/RealtimeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type RealtimeClientOptions = {
fetch?: Fetch
worker?: boolean
workerUrl?: string
accessTokenCallback?: () => Promise<string>
accessToken?: () => Promise<string>
}

export type RealtimeMessage = {
Expand Down Expand Up @@ -112,7 +112,7 @@ export default class RealtimeClient {
message: [],
}
fetch: Fetch
accessTokenCallback: (() => Promise<string>) | null = null
accessToken: (() => Promise<string>) | null = null
worker?: boolean
workerUrl?: string
workerRef?: Worker
Expand Down Expand Up @@ -182,7 +182,7 @@ export default class RealtimeClient {
this.workerUrl = options?.workerUrl
}

this.accessTokenCallback = options?.accessTokenCallback || null
this.accessToken = options?.accessToken || null
}

/**
Expand Down Expand Up @@ -394,8 +394,8 @@ export default class RealtimeClient {
ref: this.pendingHeartbeatRef,
})
// Utilizes callback if available
if (this.accessTokenCallback) {
let token = await this.accessTokenCallback()
if (this.accessToken) {
let token = await this.accessToken()
this.setAuth(token)
} else {
this.setAuth(this.accessTokenValue)
Expand Down