Skip to content

Commit

Permalink
feat(datastores): add cors origin check when fetching current user in…
Browse files Browse the repository at this point in the history
… `createAuthStore`
  • Loading branch information
hermanwikner committed Aug 10, 2022
1 parent a3f6fde commit 75129af
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/sanity/src/datastores/authStore/createAuthStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import createClient, {SanityClient} from '@sanity/client'
import {defer} from 'rxjs'
import {map, shareReplay, startWith, switchMap} from 'rxjs/operators'
import {memoize} from 'lodash'
import {checkCors, CorsOriginError} from '../cors'
import {AuthState, AuthStore} from './types'
import {createBroadcastChannel} from './createBroadcastChannel'
import {sessionId} from './sessionId'
Expand Down Expand Up @@ -83,6 +84,12 @@ const saveToken = ({token, projectId}: {token: string; projectId: string}): void
}

const getCurrentUser = async (client: SanityClient) => {
const result = await checkCors(client)

if (result?.isCorsError) {
throw new CorsOriginError({...result, projectId: client.config()?.projectId})
}

try {
const user = await client.request({
uri: '/users/me',
Expand Down

0 comments on commit 75129af

Please sign in to comment.