Skip to content

Commit 014dc69

Browse files
authored
refactor!: rename useHandleCallback → useHandleAuthCallback and HandleCallback → HandleAuthCallback (#358)
1 parent 47ef529 commit 014dc69

File tree

15 files changed

+53
-53
lines changed

15 files changed

+53
-53
lines changed

packages/core/src/_exports/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export {
2323
type LoggingInAuthState,
2424
} from '../auth/authStore'
2525
export {fetchLoginUrls} from '../auth/fetchLoginUrls'
26-
export {handleCallback} from '../auth/handleCallback'
26+
export {handleAuthCallback} from '../auth/handleAuthCallback'
2727
export {logout} from '../auth/logout'
2828
export type {ClientState} from '../client/clientStore'
2929
export {type ClientOptions, getClient, getClientState} from '../client/clientStore'

packages/core/src/auth/handleCallback.test.ts renamed to packages/core/src/auth/handleAuthCallback.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import {createSanityInstance} from '../instance/sanityInstance'
44
import {createResourceState} from '../resources/createResource'
55
import {AuthStateType} from './authStateType'
66
import {authStore} from './authStore'
7-
import {handleCallback} from './handleCallback'
7+
import {handleAuthCallback} from './handleAuthCallback'
88
import {getAuthCode, getTokenFromStorage} from './utils'
99

1010
vi.mock('./utils', async (importOriginal) => {
1111
const original = await importOriginal<typeof import('./utils')>()
1212
return {...original, getTokenFromStorage: vi.fn(), getAuthCode: vi.fn()}
1313
})
1414

15-
describe('handleCallback', () => {
15+
describe('handleAuthCallback', () => {
1616
beforeEach(() => {
1717
vi.clearAllMocks()
1818
})
@@ -37,7 +37,7 @@ describe('handleCallback', () => {
3737
const state = createResourceState(authStore.getInitialState(instance))
3838
expect(state.get()).toMatchObject({authState: {isExchangingToken: false}})
3939

40-
const resultPromise = handleCallback(
40+
const resultPromise = handleAuthCallback(
4141
{instance, state},
4242
'https://example.com/callback?foo=bar#withSid=code',
4343
)
@@ -79,7 +79,7 @@ describe('handleCallback', () => {
7979
})
8080

8181
const state = createResourceState(authStore.getInitialState(instance))
82-
const result = await handleCallback(
82+
const result = await handleAuthCallback(
8383
{instance, state},
8484
'https://example.com/callback?foo=bar#withSid=code',
8585
)
@@ -106,7 +106,7 @@ describe('handleCallback', () => {
106106
state.set('setAlreadyExchanging', {
107107
authState: {type: AuthStateType.LOGGING_IN, isExchangingToken: true},
108108
})
109-
const result = await handleCallback(
109+
const result = await handleAuthCallback(
110110
{instance, state},
111111
'https://example.com/callback?foo=bar#withSid=code',
112112
)
@@ -131,7 +131,7 @@ describe('handleCallback', () => {
131131
vi.mocked(getAuthCode).mockReturnValue(null)
132132

133133
const state = createResourceState(authStore.getInitialState(instance))
134-
const result = await handleCallback(
134+
const result = await handleAuthCallback(
135135
{instance, state},
136136
'https://example.com/callback?foo=bar#withSid=code',
137137
)
@@ -160,7 +160,7 @@ describe('handleCallback', () => {
160160
})
161161

162162
const state = createResourceState(authStore.getInitialState(instance))
163-
const result = await handleCallback(
163+
const result = await handleAuthCallback(
164164
{instance, state},
165165
'https://example.com/callback?foo=bar#withSid=code',
166166
)

packages/core/src/auth/handleCallback.ts renamed to packages/core/src/auth/handleAuthCallback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {getAuthCode, getDefaultLocation} from './utils'
77
/**
88
* @public
99
*/
10-
export const handleCallback = createAction(authStore, ({state}) => {
10+
export const handleAuthCallback = createAction(authStore, ({state}) => {
1111
const {providedToken, callbackUrl, clientFactory, apiHost, storageArea, storageKey} =
1212
state.get().options
1313

packages/react-internal/src/components/auth/LoginCallback.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import {afterAll, beforeAll, beforeEach, describe, expect, it, vi} from 'vitest'
33

44
import {renderWithWrappers} from './authTestHelpers'
55

6-
// Mock `useHandleCallback`
6+
// Mock `useHandleAuthCallback`
77
vi.mock('@sanity/sdk-react', async (importOriginal) => {
88
const actual = await importOriginal<typeof import('@sanity/sdk-react')>()
99
return {
1010
...actual,
11-
useHandleCallback: vi.fn(() => async (url: string) => {
11+
useHandleAuthCallback: vi.fn(() => async (url: string) => {
1212
const parsedUrl = new URL(url)
1313
const sid = new URLSearchParams(parsedUrl.hash.slice(1)).get('sid')
1414
if (sid === 'valid') {

packages/react-internal/src/components/auth/LoginCallback.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useHandleCallback} from '@sanity/sdk-react'
1+
import {useHandleAuthCallback} from '@sanity/sdk-react'
22
import {Flex, Heading, Spinner} from '@sanity/ui'
33
import {useEffect} from 'react'
44

@@ -13,18 +13,18 @@ import {LoginLayout, type LoginLayoutProps} from './LoginLayout'
1313
* @alpha
1414
*/
1515
export function LoginCallback({header, footer}: LoginLayoutProps): React.ReactNode {
16-
const handleCallback = useHandleCallback()
16+
const handleAuthCallback = useHandleAuthCallback()
1717

1818
useEffect(() => {
1919
const url = new URL(location.href)
20-
handleCallback(url.toString()).then((replacementLocation) => {
20+
handleAuthCallback(url.toString()).then((replacementLocation) => {
2121
if (replacementLocation) {
2222
// history API with `replaceState` is used to prevent a reload but still
2323
// remove the short-lived token from the URL
2424
history.replaceState(null, '', replacementLocation)
2525
}
2626
})
27-
}, [handleCallback])
27+
}, [handleAuthCallback])
2828

2929
return (
3030
<LoginLayout header={header} footer={footer}>

packages/react/src/_exports/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export {useAuthState} from '../hooks/auth/useAuthState'
77
export {useAuthToken} from '../hooks/auth/useAuthToken'
88
export {useCurrentUser} from '../hooks/auth/useCurrentUser'
99
export {useDashboardOrganizationId} from '../hooks/auth/useDashboardOrganizationId'
10-
export {useHandleCallback} from '../hooks/auth/useHandleCallback'
10+
export {useHandleAuthCallback} from '../hooks/auth/useHandleAuthCallback'
1111
export {useLoginUrls} from '../hooks/auth/useLoginUrls'
1212
export {useLogOut} from '../hooks/auth/useLogOut'
1313
export {useClient} from '../hooks/client/useClient'

packages/react/src/components/Login/LoginLinks.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ vi.mock('../../hooks/auth/useAuthState', () => ({
3636
useAuthState: vi.fn(() => 'logged-out'),
3737
}))
3838

39-
vi.mock('../../hooks/auth/useHandleCallback', () => ({
40-
useHandleCallback: vi.fn(),
39+
vi.mock('../../hooks/auth/useHandleAuthCallback', () => ({
40+
useHandleAuthCallback: vi.fn(),
4141
}))
4242

4343
describe('LoginLinks', () => {

packages/react/src/components/Login/LoginLinks.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {type ReactElement} from 'react'
22

33
import {useAuthState} from '../../hooks/auth/useAuthState'
4-
import {useHandleCallback} from '../../hooks/auth/useHandleCallback'
4+
import {useHandleAuthCallback} from '../../hooks/auth/useHandleAuthCallback'
55
import {useLoginUrls} from '../../hooks/auth/useLoginUrls'
66

77
/**
@@ -26,7 +26,7 @@ import {useLoginUrls} from '../../hooks/auth/useLoginUrls'
2626
export const LoginLinks = (): ReactElement => {
2727
const loginUrls = useLoginUrls()
2828
const authState = useAuthState()
29-
useHandleCallback()
29+
useHandleAuthCallback()
3030

3131
if (authState.type === 'logging-in') {
3232
return <div className="sc-login-links__logging-in">Logging in...</div>

packages/react/src/components/auth/AuthBoundary.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ vi.mock('../../hooks/auth/useAuthState', () => ({
1313
vi.mock('../../hooks/auth/useLoginUrls', () => ({
1414
useLoginUrls: vi.fn(() => [{title: 'Provider A', url: 'https://provider-a.com/auth'}]),
1515
}))
16-
vi.mock('../../hooks/auth/useHandleCallback', () => ({
17-
useHandleCallback: vi.fn(() => async () => {}),
16+
vi.mock('../../hooks/auth/useHandleAuthCallback', () => ({
17+
useHandleAuthCallback: vi.fn(() => async () => {}),
1818
}))
1919
vi.mock('../../hooks/auth/useLogOut', () => ({
2020
useLogOut: vi.fn(() => async () => {}),

packages/react/src/components/auth/LoginCallback.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import {afterAll, beforeAll, beforeEach, describe, expect, it, vi} from 'vitest'
33

44
import {renderWithWrappers} from './authTestHelpers'
55

6-
// Mock `useHandleCallback`
7-
vi.mock('../../hooks/auth/useHandleCallback', () => ({
8-
useHandleCallback: vi.fn(() => async (url: string) => {
6+
// Mock `useHandleAuthCallback`
7+
vi.mock('../../hooks/auth/useHandleAuthCallback', () => ({
8+
useHandleAuthCallback: vi.fn(() => async (url: string) => {
99
const parsedUrl = new URL(url)
1010
const sid = new URLSearchParams(parsedUrl.hash.slice(1)).get('sid')
1111
if (sid === 'valid') {

0 commit comments

Comments
 (0)