Skip to content

Commit

Permalink
fix(ozone): adapt to latest oauth-client changes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieusieben committed Jun 21, 2024
1 parent 1c79b49 commit ad13d2e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions components/shell/auth/oauth/useOAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
BrowserOAuthClientOptions,
LoginContinuedInParentWindowError,
OAuthAgent,
OAuthClientIdLoopback,
OAuthClientMetadataInput,
} from '@atproto/oauth-client-browser'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
Expand Down Expand Up @@ -38,7 +39,8 @@ function useCallbackRef<T extends (this: any, ...args: any[]) => any>(fn?: T) {
): void | ReturnType<T> {
const { current } = fnRef
if (current) return current.call(this, ...args)
}, [])
},
[])
}

type ClientOptions =
Expand Down Expand Up @@ -76,19 +78,23 @@ function useOAuthClient(
plcDirectoryUrl,
} = options

const optionsClientMetadata: null | 'auto' | OAuthClientMetadataInput =
const optionsClientMetadata:
| null
| 'forced'
| OAuthClientMetadataInput
| OAuthClientIdLoopback =
!optionClient && (!clientId || clientMetadata != null)
? clientMetadata || 'auto'
? clientMetadata || 'forced'
: null

const fetch = useCallbackRef(options.fetch || globalThis.fetch)

const oauthClientOptions = useMemo<null | BrowserOAuthClientOptions>(
() =>
optionsClientMetadata
optionsClientMetadata && handleResolver
? {
clientMetadata:
optionsClientMetadata === 'auto'
optionsClientMetadata === 'forced'
? undefined
: optionsClientMetadata,
handleResolver,
Expand All @@ -111,7 +117,7 @@ function useOAuthClient(

const optionsLoad = useMemo<null | BrowserOAuthClientLoadOptions>(
() =>
optionsClientId
optionsClientId && handleResolver
? {
clientId: optionsClientId,
handleResolver,
Expand Down

0 comments on commit ad13d2e

Please sign in to comment.