mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-23 15:42:09 -05:00
chore: lint & format
This commit is contained in:
committed by
Gustavo Valverde
parent
4cf4f768e9
commit
862bba4c65
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user