From bc82bf3d30db1e4ebb15bc1850c00d96aa6fc59e Mon Sep 17 00:00:00 2001 From: Bereket Engida Date: Tue, 24 Sep 2024 02:10:48 +0300 Subject: [PATCH] test: providers --- packages/better-auth/src/api/index.ts | 54 +--- .../better-auth/src/api/routes/callback.ts | 12 +- .../better-auth/src/api/routes/session.ts | 262 ++++++++++-------- .../better-auth/src/api/routes/sign-up.ts | 8 +- packages/better-auth/src/client/proxy.ts | 2 - packages/better-auth/src/client/query.ts | 1 - .../better-auth/src/client/session-atom.ts | 4 +- .../src/plugins/rate-limiter/get-key.ts | 2 +- .../plugins/rate-limiter/rate-limiter.test.ts | 2 +- .../better-auth/src/social-providers/apple.ts | 43 ++- .../src/social-providers/providers.test.ts | 93 +++++++ 11 files changed, 270 insertions(+), 213 deletions(-) create mode 100644 packages/better-auth/src/social-providers/providers.test.ts diff --git a/packages/better-auth/src/api/index.ts b/packages/better-auth/src/api/index.ts index 13955134e3..828e719261 100644 --- a/packages/better-auth/src/api/index.ts +++ b/packages/better-auth/src/api/index.ts @@ -5,8 +5,8 @@ import { createRouter, } from "better-call"; import type { AuthContext } from "../init"; -import type { BetterAuthOptions, InferSession, InferUser } from "../types"; -import type { Prettify, UnionToIntersection } from "../types/helper"; +import type { BetterAuthOptions } from "../types"; +import type { UnionToIntersection } from "../types/helper"; import { csrfMiddleware } from "./middlewares/csrf"; import { callbackOAuth, @@ -78,56 +78,11 @@ export function getEndpoints< .filter((plugin) => plugin !== undefined) .flat() || []; - /** - * Helper function to type the session output - * TODO: find a better way to do this - */ - async function typedSession( - ctx: Context< - "/session", - { - method: "GET"; - requireHeaders: true; - } - >, - ) { - const handler = await getSession(ctx); - return handler as { - session: Prettify>; - user: Prettify>; - } | null; - } - typedSession.path = getSession.path; - typedSession.method = getSession.method; - typedSession.options = getSession.options; - typedSession.headers = getSession.headers; - - /** - * Helper function to type the list sessions output - * TODO: find a better way to do this - */ - async function typeListSessions( - ctx: Context< - "/user/sessions", - { - method: "GET"; - requireHeaders: true; - } - >, - ) { - const handler = await listSessions(ctx); - return handler as unknown as Prettify>[]; - } - typeListSessions.path = listSessions.path; - typeListSessions.method = listSessions.method; - typeListSessions.options = listSessions.options; - typeListSessions.headers = listSessions.headers; - const baseEndpoints = { signInOAuth, callbackOAuth, getCSRFToken, - getSession: typedSession, + getSession: getSession