diff --git a/packages/react/src/auth/index.ts b/packages/react/src/auth/index.ts index 24520331..44c26463 100644 --- a/packages/react/src/auth/index.ts +++ b/packages/react/src/auth/index.ts @@ -20,7 +20,7 @@ export { useSendSignInLinkToEmailMutation } from "./useSendSignInLinkToEmailMutation"; export { useSignInAnonymouslyMutation } from "./useSignInAnonymouslyMutation"; // useSignInWithCredentialMutation -// useSignInWithCustomTokenMutation +export { useSignInWithCustomTokenMutation } from "./useSignInWithCustomTokenMutation"; // useSignInWithEmailAndPasswordMutation // useSignInWithEmailLinkMutation // useSignInWithPhoneNumberMutation diff --git a/packages/react/src/auth/useSignInWithCustomTokenMutation.test.tsx b/packages/react/src/auth/useSignInWithCustomTokenMutation.test.tsx new file mode 100644 index 00000000..c62ad608 --- /dev/null +++ b/packages/react/src/auth/useSignInWithCustomTokenMutation.test.tsx @@ -0,0 +1,39 @@ +import React from "react"; +import { + describe, + expect, + test, + beforeEach, + afterEach, + vi, + type MockInstance, +} from "vitest"; +import { renderHook, act, waitFor } from "@testing-library/react"; +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { useSignInWithCustomTokenMutation } from "./useSignInWithCustomTokenMutation"; +import { auth, wipeAuth } from "~/testing-utils"; +import {} from "firebase/auth"; + +const queryClient = new QueryClient({ + defaultOptions: { + queries: { retry: false }, + mutations: { retry: false }, + }, +}); + +const wrapper = ({ children }: { children: React.ReactNode }) => ( + {children} +); + +describe("useSignInWithCustomTokenMutation", () => { + beforeEach(async () => { + queryClient.clear(); + await wipeAuth(); + }); + + afterEach(async () => { + await auth.signOut(); + }); + + test("successfully signs in with a valid custom token", async () => {}); +}); diff --git a/packages/react/src/auth/useSignInWithCustomTokenMutation.ts b/packages/react/src/auth/useSignInWithCustomTokenMutation.ts new file mode 100644 index 00000000..8f4e32de --- /dev/null +++ b/packages/react/src/auth/useSignInWithCustomTokenMutation.ts @@ -0,0 +1,23 @@ +import { useMutation, UseMutationOptions } from "@tanstack/react-query"; +import { + signInWithCustomToken, + type Auth, + type AuthError, + type UserCredential, +} from "firebase/auth"; + +type AuthUseMutationOptions< + TData = unknown, + TError = Error, + TVariables = void +> = Omit, "mutationFn">; + +export function useSignInWithCustomTokenMutation( + auth: Auth, + options?: AuthUseMutationOptions +) { + return useMutation({ + ...options, + mutationFn: (customToken) => signInWithCustomToken(auth, customToken), + }); +}