@rolder/kit 3.0.0-alpha.95 → 3.0.0-alpha.97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2799,12 +2799,12 @@ export declare const getAuthClient: <TRoles extends Record<string, Role>>(config
2799
2799
  emailVerified: boolean;
2800
2800
  name: string;
2801
2801
  image?: string | null | undefined;
2802
- username?: string | null | undefined;
2803
- displayUsername?: string | null | undefined;
2804
2802
  banned: boolean | null | undefined;
2805
2803
  role?: string | null | undefined;
2806
2804
  banReason?: string | null | undefined;
2807
2805
  banExpires?: Date | null | undefined;
2806
+ username?: string | null | undefined;
2807
+ displayUsername?: string | null | undefined;
2808
2808
  };
2809
2809
  session: {
2810
2810
  id: string;
@@ -2850,12 +2850,12 @@ export declare const getAuthClient: <TRoles extends Record<string, Role>>(config
2850
2850
  emailVerified: boolean;
2851
2851
  name: string;
2852
2852
  image?: string | null | undefined;
2853
- username?: string | null | undefined;
2854
- displayUsername?: string | null | undefined;
2855
2853
  banned: boolean | null | undefined;
2856
2854
  role?: string | null | undefined;
2857
2855
  banReason?: string | null | undefined;
2858
2856
  banExpires?: Date | null | undefined;
2857
+ username?: string | null | undefined;
2858
+ displayUsername?: string | null | undefined;
2859
2859
  };
2860
2860
  session: {
2861
2861
  id: string;
@@ -2886,12 +2886,12 @@ export declare const getAuthClient: <TRoles extends Record<string, Role>>(config
2886
2886
  emailVerified: boolean;
2887
2887
  name: string;
2888
2888
  image?: string | null | undefined;
2889
- username?: string | null | undefined;
2890
- displayUsername?: string | null | undefined;
2891
2889
  banned: boolean | null | undefined;
2892
2890
  role?: string | null | undefined;
2893
2891
  banReason?: string | null | undefined;
2894
2892
  banExpires?: Date | null | undefined;
2893
+ username?: string | null | undefined;
2894
+ displayUsername?: string | null | undefined;
2895
2895
  };
2896
2896
  session: {
2897
2897
  id: string;
@@ -0,0 +1,7 @@
1
+ import type { BetterAuthOptions } from 'better-auth/minimal';
2
+ import { type Role } from 'better-auth/plugins';
3
+ export interface AuthServerConfig {
4
+ betterAuthOptions?: Partial<BetterAuthOptions>;
5
+ roles?: Record<string, Role>;
6
+ }
7
+ export declare const getAuthServerConfig: (config?: AuthServerConfig) => BetterAuthOptions;
@@ -1,13 +1,12 @@
1
- import { betterAuth } from "better-auth";
2
- import { admin, customSession, jwt, username } from "better-auth/plugins";
1
+ import { admin, jwt, username } from "better-auth/plugins";
3
2
  import { defaultRoles } from "better-auth/plugins/admin/access";
4
3
  import { tanstackStartCookies } from "better-auth/tanstack-start";
5
4
  import { surrealDbAdapter } from "./surrealDbAdapter/index.js";
6
5
  const baseUrl = "/";
7
- const getAuthServer = (config)=>{
6
+ const getAuthServerConfig = (config)=>{
8
7
  const roles = config?.roles || defaultRoles;
9
8
  const betterAuthOptions = config?.betterAuthOptions;
10
- const resultOptions = {
9
+ return {
11
10
  baseURL: baseUrl,
12
11
  secret: process.env.BETTER_AUTH_SECRET,
13
12
  database: surrealDbAdapter(),
@@ -24,20 +23,7 @@ const getAuthServer = (config)=>{
24
23
  bannedUserMessage: 'Доступ к приложению заблокирован. Обратитесь к администратору.'
25
24
  }),
26
25
  username(),
27
- ...betterAuthOptions?.plugins || []
28
- ]
29
- };
30
- const auth = betterAuth({
31
- ...resultOptions,
32
- plugins: [
33
- ...resultOptions.plugins,
34
- customSession(async ({ user, session })=>({
35
- user: {
36
- ...user,
37
- role: user.role
38
- },
39
- session
40
- }), resultOptions),
26
+ ...betterAuthOptions?.plugins || [],
41
27
  jwt({
42
28
  jwks: {
43
29
  keyPairConfig: {
@@ -63,7 +49,6 @@ const getAuthServer = (config)=>{
63
49
  }),
64
50
  tanstackStartCookies()
65
51
  ]
66
- });
67
- return auth;
52
+ };
68
53
  };
69
- export { getAuthServer };
54
+ export { getAuthServerConfig };
@@ -1,9 +1,9 @@
1
- export { betterAuth } from 'better-auth';
2
1
  export * from 'better-auth/client/plugins';
2
+ export { betterAuth as betterAuthServer } from 'better-auth/minimal';
3
3
  export * from 'better-auth/plugins';
4
4
  export * from 'better-auth/plugins/admin/access';
5
5
  export * from 'better-auth/react';
6
6
  export { tanstackStartCookies } from 'better-auth/tanstack-start';
7
- export * from './getAuthServer';
7
+ export * from './getAuthServerConfig';
8
8
  export * from './getDBSession';
9
9
  export * from './getSessionUser';
@@ -1,10 +1,10 @@
1
- import { betterAuth } from "better-auth";
1
+ import { betterAuth } from "better-auth/minimal";
2
2
  import { tanstackStartCookies } from "better-auth/tanstack-start";
3
3
  export * from "better-auth/client/plugins";
4
4
  export * from "better-auth/plugins";
5
5
  export * from "better-auth/plugins/admin/access";
6
6
  export * from "better-auth/react";
7
- export * from "./getAuthServer.js";
7
+ export * from "./getAuthServerConfig.js";
8
8
  export * from "./getDBSession.js";
9
9
  export * from "./getSessionUser.js";
10
- export { betterAuth, tanstackStartCookies };
10
+ export { betterAuth as betterAuthServer, tanstackStartCookies };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolder/kit",
3
- "version": "3.0.0-alpha.95",
3
+ "version": "3.0.0-alpha.97",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./ai": {
@@ -1 +0,0 @@
1
- export {};
@@ -1,71 +0,0 @@
1
- import { beforeAll, describe, expect, it } from "vitest";
2
- const ensureDbEnv = ()=>{
3
- process.env.SURREALDB_DATABASE = 'tests';
4
- };
5
- const hasDbEnv = ()=>Boolean(process.env.SURREALDB_URL && process.env.SURREALDB_NAMESPACE && process.env.SURREALDB_USERNAME && process.env.SURREALDB_PASSWORD);
6
- let auth;
7
- const createUser = ()=>{
8
- const id = crypto.randomUUID();
9
- return {
10
- name: 'Test User',
11
- email: `test.user+${id}@example.com`,
12
- password: 'password-123'
13
- };
14
- };
15
- describe.skipIf(!hasDbEnv())('better auth', ()=>{
16
- beforeAll(async ()=>{
17
- ensureDbEnv();
18
- auth = (await import("./index.js")).getAuthServer();
19
- });
20
- it('rejects protected endpoints without a session', async ()=>{
21
- const request = new Request('http://localhost/api/auth/list-accounts');
22
- const response = await auth.handler(request);
23
- expect([
24
- 401,
25
- 403
26
- ]).toContain(response.status);
27
- });
28
- it('supports sign-up and sign-in with session retrieval', async ()=>{
29
- const origin = 'http://localhost';
30
- const user = createUser();
31
- const signUpRequest = new Request('http://localhost/api/auth/sign-up/email', {
32
- method: 'POST',
33
- headers: {
34
- 'content-type': 'application/json',
35
- origin
36
- },
37
- body: JSON.stringify({
38
- name: user.name,
39
- email: user.email,
40
- password: user.password
41
- })
42
- });
43
- const signUpResponse = await auth.handler(signUpRequest);
44
- expect(signUpResponse.status).toBe(200);
45
- const signInRequest = new Request('http://localhost/api/auth/sign-in/email', {
46
- method: 'POST',
47
- headers: {
48
- 'content-type': 'application/json',
49
- origin
50
- },
51
- body: JSON.stringify({
52
- email: user.email,
53
- password: user.password
54
- })
55
- });
56
- const signInResponse = await auth.handler(signInRequest);
57
- expect(signInResponse.status).toBe(200);
58
- const setCookie = signInResponse.headers.get('set-cookie');
59
- expect(setCookie).toBeTruthy();
60
- const cookie = setCookie?.split(';')[0];
61
- const sessionRequest = new Request('http://localhost/api/auth/get-session', {
62
- headers: cookie ? {
63
- cookie
64
- } : void 0
65
- });
66
- const sessionResponse = await auth.handler(sessionRequest);
67
- expect(sessionResponse.status).toBe(200);
68
- const sessionBody = await sessionResponse.json();
69
- expect(sessionBody?.user?.email).toBe(user.email);
70
- });
71
- });
@@ -1,8 +0,0 @@
1
- import type { BetterAuthOptions } from 'better-auth';
2
- import { betterAuth } from 'better-auth';
3
- import { type Role } from 'better-auth/plugins';
4
- export interface AuthServer<TRoles extends Record<string, Role>> {
5
- betterAuthOptions?: Partial<BetterAuthOptions>;
6
- roles?: TRoles;
7
- }
8
- export declare const getAuthServer: <TRoles extends Record<string, Role>>(config?: AuthServer<TRoles>) => ReturnType<typeof betterAuth>;