chore: lint & format

This commit is contained in:
yacobmole
2025-12-11 10:35:21 +11:00
committed by Gustavo Valverde
parent 4cf4f768e9
commit 862bba4c65
2 changed files with 36 additions and 36 deletions

View File

@@ -3,25 +3,25 @@ import type { Auth } from "../types";
import { betterAuth } from "./custom";
describe("auth-custom", () => {
test("default auth type should be okay (no interceptor)", () => {
const auth = betterAuth({});
type T = typeof auth;
expectTypeOf<T>().toEqualTypeOf<Auth>();
});
test("default auth type should be okay (with interceptor)", () => {
const auth = betterAuth({}, (ctx) => ctx);
type T = typeof auth;
expectTypeOf<T>().toEqualTypeOf<Auth>();
});
test("an invalid interceptor type should throw", () => {
expect(() => betterAuth({}, "not an interceptor" as any)).toThrow();
});
test("context should be modified all the way down", async () => {
const auth = betterAuth({}, (ctx) => {
ctx.appName = "My Different App Name";
return ctx;
});
const newContext = await auth.$context;
expect(newContext.appName).toBe("My Different App Name");
});
test("default auth type should be okay (no interceptor)", () => {
const auth = betterAuth({});
type T = typeof auth;
expectTypeOf<T>().toEqualTypeOf<Auth>();
});
test("default auth type should be okay (with interceptor)", () => {
const auth = betterAuth({}, (ctx) => ctx);
type T = typeof auth;
expectTypeOf<T>().toEqualTypeOf<Auth>();
});
test("an invalid interceptor type should throw", () => {
expect(() => betterAuth({}, "not an interceptor" as any)).toThrow();
});
test("context should be modified all the way down", async () => {
const auth = betterAuth({}, (ctx) => {
ctx.appName = "My Different App Name";
return ctx;
});
const newContext = await auth.$context;
expect(newContext.appName).toBe("My Different App Name");
});
});

View File

@@ -14,22 +14,22 @@ import { createBetterAuth } from "./base";
*/
export const betterAuth = <Options extends BetterAuthOptions>(
options: Options &
// fixme(alex): do we need Record<never, never> here?
Record<never, never>,
contextInterceptor?: (ctx: AuthContext) => AuthContext,
options: Options &
// fixme(alex): do we need Record<never, never> here?
Record<never, never>,
contextInterceptor?: (ctx: AuthContext) => AuthContext,
): Auth<Options> => {
const isValidInterceptor = typeof contextInterceptor === "function";
const interceptor = isValidInterceptor
? contextInterceptor
: (ctx: AuthContext) => ctx;
const isValidInterceptor = typeof contextInterceptor === "function";
const interceptor = isValidInterceptor
? contextInterceptor
: (ctx: AuthContext) => ctx;
if (!isValidInterceptor && contextInterceptor !== undefined) {
throw new BetterAuthError(
"Provided contextInterceptor is not a valid function",
);
}
if (!isValidInterceptor && contextInterceptor !== undefined) {
throw new BetterAuthError(
"Provided contextInterceptor is not a valid function",
);
}
const initFn = (options: Options) => init(options).then(interceptor);
return createBetterAuth(options, initFn);
const initFn = (options: Options) => init(options).then(interceptor);
return createBetterAuth(options, initFn);
};