Skip to content

Commit

Permalink
perf(useSupabaseAuthClient): avoid declaring unused variables (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianGlowala committed Mar 31, 2023
1 parent 994329e commit 8c070b9
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/runtime/composables/useSupabaseAuthClient.ts
Expand Up @@ -5,16 +5,17 @@ import { useRuntimeConfig, useNuxtApp } from '#imports'

export const useSupabaseAuthClient = <T>(): SupabaseClient<T> => {
const nuxtApp = useNuxtApp()
const token = useSupabaseToken()
const Authorization = token.value ? `Bearer ${token.value}` : undefined

const { supabase: { url, key, client: clientOptions } } = useRuntimeConfig().public
// Create auth client if doesn't already exist
if (!nuxtApp._supabaseAuthClient) {
const token = useSupabaseToken()
const authorizationHeader = token.value ? `Bearer ${token.value}` : undefined

// Set auth header
const options = Authorization ? defu(clientOptions, { global: { headers: { Authorization } } }) : clientOptions
const { supabase: { url, key, client: clientOptions } } = useRuntimeConfig().public

// Set auth header
const options = authorizationHeader ? defu(clientOptions, { global: { headers: { Authorization: authorizationHeader } } }) : clientOptions

// No need to recreate client if exists
if (!nuxtApp._supabaseAuthClient) {
nuxtApp._supabaseAuthClient = createClient(url, key, options)
}

Expand Down

0 comments on commit 8c070b9

Please sign in to comment.