From 37e54f62cf81051f90af851ebc721eb4c5b74303 Mon Sep 17 00:00:00 2001 From: Juan Cardenas Date: Sun, 11 Aug 2024 09:44:14 -0500 Subject: [PATCH 1/2] fix: fix type, remove unused imports, define AuthEvent type --- src/createServerClient.ts | 13 +++---------- src/types.ts | 8 ++++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/createServerClient.ts b/src/createServerClient.ts index c59edb1..a803759 100644 --- a/src/createServerClient.ts +++ b/src/createServerClient.ts @@ -5,19 +5,12 @@ import type { } from "@supabase/supabase-js/dist/module/lib/types"; import { VERSION } from "./version"; -import { - DEFAULT_COOKIE_OPTIONS, - combineChunks, - createChunks, - deleteChunks, - isBrowser, - isChunkLike, -} from "./utils"; import { createStorageFromOptions, applyServerStorage } from "./cookies"; import type { CookieOptionsWithName, CookieMethodsServer, CookieMethodsServerDeprecated, + AuthEvent, } from "./types"; /** @@ -75,7 +68,7 @@ export function createServerClient< * **Use in pages, components or routes.** * * To use Supabase features server-side rendered in pages, components or routes - * (a.k.a. actions / APIs) you must create a client with this funciton. Not all + * (a.k.a. actions / APIs) you must create a client with this function. Not all * frameworks allow the ability to set cookies or response headers when pages * or components are rendered. In those cases you _can omit `setAll` (or the * deprecated `set`, `remove`) cookie option methods_. **It is strongly @@ -180,7 +173,7 @@ export function createServerClient< }, ); - client.auth.onAuthStateChange(async (event) => { + client.auth.onAuthStateChange(async (event: AuthEvent) => { // The SIGNED_IN event is fired very often, but we don't need to // apply the storage each time it fires, only if there are changes // that need to be set -- which is if setItems / removeItems have diff --git a/src/types.ts b/src/types.ts index 043f363..460b43a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -47,3 +47,11 @@ export type CookieMethodsServer = { getAll: GetAllCookies; setAll?: SetAllCookies; }; + +export type AuthEvent = + | "SIGNED_IN" + | "TOKEN_REFRESHED" + | "USER_UPDATED" + | "PASSWORD_RECOVERY" + | "SIGNED_OUT" + | "MFA_CHALLENGE_VERIFIED"; From fb574bb7cf89343af2a219d76a0b7b4482be6d40 Mon Sep 17 00:00:00 2001 From: Juan Cardenas Date: Tue, 3 Sep 2024 21:46:43 -0500 Subject: [PATCH 2/2] fix: take type definition from supabase-js library --- src/createServerClient.ts | 9 ++++++--- src/types.ts | 8 -------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/createServerClient.ts b/src/createServerClient.ts index a803759..c4f3d6a 100644 --- a/src/createServerClient.ts +++ b/src/createServerClient.ts @@ -1,4 +1,8 @@ -import { createClient, SupabaseClient } from "@supabase/supabase-js"; +import { + AuthChangeEvent, + createClient, + SupabaseClient, +} from "@supabase/supabase-js"; import type { GenericSchema, SupabaseClientOptions, @@ -10,7 +14,6 @@ import type { CookieOptionsWithName, CookieMethodsServer, CookieMethodsServerDeprecated, - AuthEvent, } from "./types"; /** @@ -173,7 +176,7 @@ export function createServerClient< }, ); - client.auth.onAuthStateChange(async (event: AuthEvent) => { + client.auth.onAuthStateChange(async (event: AuthChangeEvent) => { // The SIGNED_IN event is fired very often, but we don't need to // apply the storage each time it fires, only if there are changes // that need to be set -- which is if setItems / removeItems have diff --git a/src/types.ts b/src/types.ts index 460b43a..043f363 100644 --- a/src/types.ts +++ b/src/types.ts @@ -47,11 +47,3 @@ export type CookieMethodsServer = { getAll: GetAllCookies; setAll?: SetAllCookies; }; - -export type AuthEvent = - | "SIGNED_IN" - | "TOKEN_REFRESHED" - | "USER_UPDATED" - | "PASSWORD_RECOVERY" - | "SIGNED_OUT" - | "MFA_CHALLENGE_VERIFIED";