@vite-hub/auth 0.4.1 → 0.5.0

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.
Files changed (66) hide show
  1. package/README.md +31 -7
  2. package/dist/{abilities-CbmTAoS_.d.ts → abilities-9jC7iuN0.d.ts} +2 -2
  3. package/dist/abilities.d.ts +1 -1
  4. package/dist/{ability-error-DcgChwCN.d.ts → ability-error-DUWJ6Q1W.d.ts} +1 -1
  5. package/dist/{ability-error-IeZQBr_-.js → ability-error-DmnUGicq.js} +1 -1
  6. package/dist/access-pages-FNQTyGRD.js +96 -0
  7. package/dist/agent.js +3 -3
  8. package/dist/{auth-instance-CmDogt4D.js → auth-instance-zYMjldPG.js} +227 -25
  9. package/dist/{cli-ubYJpAL_.d.ts → cli-NCtitmny.d.ts} +1 -0
  10. package/dist/cli.d.ts +1 -1
  11. package/dist/cli.js +1 -1
  12. package/dist/{console-runtime-_LrpyCYY.js → console-runtime-CuXRDhGy.js} +67 -33
  13. package/dist/{console-runtime-D2ai-Et5.d.ts → console-runtime-Dqidb3zF.d.ts} +13 -11
  14. package/dist/console-runtime.d.ts +2 -2
  15. package/dist/console-runtime.js +1 -1
  16. package/dist/console.d.ts +1 -1
  17. package/dist/{database-options-DpOVjUti.js → database-options-CcjUG-us.js} +1 -1
  18. package/dist/{database-schema-options-Sk-1Bvyu.js → database-schema-options-CTKCAfqW.js} +1 -1
  19. package/dist/database.d.ts +1 -1
  20. package/dist/database.js +4 -4
  21. package/dist/{definition-BCaLA9kW.js → definition-BFT9T6In.js} +12 -4
  22. package/dist/{error-diagnostics-Dymr-S_n.js → error-diagnostics-uEbxSY2G.js} +8 -2
  23. package/dist/{events-DCfuicoo.js → events-DJmO9a9I.js} +1 -1
  24. package/dist/forward.js +1 -1
  25. package/dist/index.d.ts +3 -2
  26. package/dist/index.js +4 -3
  27. package/dist/internal/server.d.ts +4 -4
  28. package/dist/internal/server.js +4 -4
  29. package/dist/{invariant-D8_xBqmZ.js → invariant-DolT9EEx.js} +1 -1
  30. package/dist/{mcp-token-CpxLyl_p.js → mcp-token-BhonlK9C.js} +2 -2
  31. package/dist/mcp.js +1 -1
  32. package/dist/{members-DdlsS8kJ.js → members-Cl3hFRjk.js} +3 -3
  33. package/dist/nitro-kit-32CVgbWS.js +44 -0
  34. package/dist/nuxt.d.ts +32 -19
  35. package/dist/nuxt.js +337 -16
  36. package/dist/own-access-C8pwo_Kn.js +31 -0
  37. package/dist/own-access-CdgEICjO.d.ts +20 -0
  38. package/dist/presets.js +1 -1
  39. package/dist/runtime/console.d.ts +1 -1
  40. package/dist/runtime/console.js +2 -2
  41. package/dist/runtime/empty-abilities.d.ts +1 -1
  42. package/dist/runtime/empty-definition.d.ts +1 -1
  43. package/dist/runtime/server.d.ts +3 -2
  44. package/dist/runtime/server.js +23 -14
  45. package/dist/runtime/vue-nuxt.js +70 -28
  46. package/dist/schema.d.ts +71 -19
  47. package/dist/schema.js +5 -3
  48. package/dist/{server-C8TlOrSy.d.ts → server-B-zNtSvm.d.ts} +9 -10
  49. package/dist/{server-BM-RSf1T.d.ts → server-Ci2i6p1S.d.ts} +7 -6
  50. package/dist/{server-BG_MFd4q.js → server-CyqLFm3L.js} +45 -25
  51. package/dist/server.d.ts +2 -2
  52. package/dist/server.js +2 -2
  53. package/dist/{session-cookies-DVzjOKc7.js → session-cookies-CZmZS5QF.js} +2 -2
  54. package/dist/{set-cookie-DmqWq6kj.js → set-cookie-DWIyCCJO.js} +1 -1
  55. package/dist/{table-specs-DbXyaXWs.d.ts → table-specs-BhWz_U0M.d.ts} +255 -1
  56. package/dist/{table-specs-CURphR3n.js → table-specs-D0VLp1U4.js} +43 -43
  57. package/dist/test.d.ts +1 -1
  58. package/dist/test.js +2 -2
  59. package/dist/{types-CruflEFI.d.ts → types-gl-myjZc.d.ts} +51 -4
  60. package/dist/{vite-Dy0Xhq4H.js → vite-QKjsPLwP.js} +349 -120
  61. package/dist/vite.d.ts +6 -2
  62. package/dist/vite.js +1 -1
  63. package/dist/vue.d.ts +17 -68
  64. package/dist/vue.js +22 -69
  65. package/package.json +13 -9
  66. package/dist/shared-DRtfuFsV.js +0 -12
package/dist/server.js CHANGED
@@ -1,3 +1,3 @@
1
- import { t as AbilityError } from "./ability-error-IeZQBr_-.js";
2
- import { D as withAuthorization, E as withAuth, S as signOut, T as withAnonymousAuthorization, _ as requireAbility, a as checkAuthMember, b as requireAuthorization, f as getAuthConsoleForRequest, g as listAuthEvents, i as can, l as createAuthHandler, m as handleAuth, p as getAuthEvents, r as authRoute, t as aggregateAuthEvents, v as requireAuth, w as useAuth, x as requireCaller } from "./server-BG_MFd4q.js";
1
+ import { t as AbilityError } from "./ability-error-DmnUGicq.js";
2
+ import { D as withAuthorization, E as withAuth, S as signOut, T as withAnonymousAuthorization, _ as requireAbility, a as checkAuthMember, b as requireAuthorization, f as getAuthConsoleForRequest, g as listAuthEvents, i as can, l as createAuthHandler, m as handleAuth, p as getAuthEvents, r as authRoute, t as aggregateAuthEvents, v as requireAuth, w as useAuth, x as requireCaller } from "./server-CyqLFm3L.js";
3
3
  export { AbilityError, aggregateAuthEvents, can, checkAuthMember, createAuthHandler, authRoute as default, getAuthConsoleForRequest, getAuthEvents, handleAuth, listAuthEvents, requireAbility, requireAuth, requireAuthorization, requireCaller, signOut, useAuth, withAnonymousAuthorization, withAuth, withAuthorization };
@@ -1,5 +1,5 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-Dymr-S_n.js";
2
- import { r as throwAuthenticationProviderError, t as readSetCookies } from "./set-cookie-DmqWq6kj.js";
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-uEbxSY2G.js";
2
+ import { r as throwAuthenticationProviderError, t as readSetCookies } from "./set-cookie-DWIyCCJO.js";
3
3
  import { t as isRecord } from "./object-Da1zyPCR.js";
4
4
  import { n as authRequestEvent } from "./request-z6DHHmrb.js";
5
5
  import { HTTPError } from "nitro/h3";
@@ -1,4 +1,4 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-Dymr-S_n.js";
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-uEbxSY2G.js";
2
2
  import { ViteHubError, isViteHubError } from "@vite-hub/runtime";
3
3
  //#region src/errors.ts
4
4
  function invalidAuthenticationErrorOptions() {
@@ -820,6 +820,260 @@ interface AuthPluginSchema {
820
820
  /** Tables that the plugin adds. */
821
821
  tables?: Readonly<Record<string, AuthTableSpec>>;
822
822
  }
823
+ declare const pluginSchemas: {
824
+ readonly anonymous: {
825
+ readonly fields: {
826
+ readonly user: {
827
+ readonly isAnonymous: {
828
+ readonly type: "boolean";
829
+ readonly defaultValue: false;
830
+ };
831
+ };
832
+ };
833
+ };
834
+ readonly apiKey: {
835
+ readonly tables: {
836
+ readonly apikey: {
837
+ readonly fields: {
838
+ readonly configId: {
839
+ readonly type: "string";
840
+ readonly required: true;
841
+ readonly index: true;
842
+ readonly defaultValue: "default";
843
+ };
844
+ readonly name: {
845
+ readonly type: "string";
846
+ };
847
+ readonly start: {
848
+ readonly type: "string";
849
+ };
850
+ readonly referenceId: {
851
+ readonly type: "string";
852
+ readonly required: true;
853
+ readonly index: true;
854
+ };
855
+ readonly prefix: {
856
+ readonly type: "string";
857
+ };
858
+ readonly key: {
859
+ readonly type: "string";
860
+ readonly required: true;
861
+ readonly index: true;
862
+ };
863
+ readonly refillInterval: {
864
+ readonly type: "number";
865
+ readonly bigint: true;
866
+ };
867
+ readonly refillAmount: {
868
+ readonly type: "number";
869
+ };
870
+ readonly lastRefillAt: {
871
+ readonly type: "date";
872
+ };
873
+ readonly enabled: {
874
+ readonly type: "boolean";
875
+ readonly defaultValue: true;
876
+ };
877
+ readonly rateLimitEnabled: {
878
+ readonly type: "boolean";
879
+ readonly defaultValue: true;
880
+ };
881
+ readonly rateLimitTimeWindow: {
882
+ readonly type: "number";
883
+ readonly bigint: true;
884
+ readonly defaultValue: 86_400_000;
885
+ };
886
+ readonly rateLimitMax: {
887
+ readonly type: "number";
888
+ readonly defaultValue: 10;
889
+ };
890
+ readonly requestCount: {
891
+ readonly type: "number";
892
+ readonly defaultValue: 0;
893
+ };
894
+ readonly remaining: {
895
+ readonly type: "number";
896
+ };
897
+ readonly lastRequest: {
898
+ readonly type: "date";
899
+ };
900
+ readonly expiresAt: {
901
+ readonly type: "date";
902
+ };
903
+ readonly createdAt: {
904
+ readonly type: "date";
905
+ readonly required: true;
906
+ };
907
+ readonly updatedAt: {
908
+ readonly type: "date";
909
+ readonly required: true;
910
+ };
911
+ readonly permissions: {
912
+ readonly type: "string";
913
+ };
914
+ readonly metadata: {
915
+ readonly type: "string";
916
+ };
917
+ };
918
+ };
919
+ };
920
+ };
921
+ readonly lastLoginMethod: {
922
+ readonly fields: {
923
+ readonly user: {
924
+ readonly lastLoginMethod: {
925
+ readonly type: "string";
926
+ };
927
+ };
928
+ };
929
+ };
930
+ readonly phoneNumber: {
931
+ readonly fields: {
932
+ readonly user: {
933
+ readonly phoneNumber: {
934
+ readonly type: "string";
935
+ readonly unique: true;
936
+ };
937
+ readonly phoneNumberVerified: {
938
+ readonly type: "boolean";
939
+ };
940
+ };
941
+ };
942
+ };
943
+ readonly stripe: {
944
+ readonly fields: {
945
+ readonly user: {
946
+ readonly stripeCustomerId: {
947
+ readonly type: "string";
948
+ };
949
+ };
950
+ readonly organization: {
951
+ readonly stripeCustomerId: {
952
+ readonly type: "string";
953
+ };
954
+ };
955
+ };
956
+ readonly tables: {
957
+ readonly subscription: {
958
+ readonly fields: {
959
+ readonly plan: {
960
+ readonly type: "string";
961
+ readonly required: true;
962
+ };
963
+ readonly referenceId: {
964
+ readonly type: "string";
965
+ readonly required: true;
966
+ };
967
+ readonly stripeCustomerId: {
968
+ readonly type: "string";
969
+ };
970
+ readonly stripeSubscriptionId: {
971
+ readonly type: "string";
972
+ };
973
+ readonly status: {
974
+ readonly type: "string";
975
+ readonly defaultValue: "incomplete";
976
+ };
977
+ readonly periodStart: {
978
+ readonly type: "date";
979
+ };
980
+ readonly periodEnd: {
981
+ readonly type: "date";
982
+ };
983
+ readonly trialStart: {
984
+ readonly type: "date";
985
+ };
986
+ readonly trialEnd: {
987
+ readonly type: "date";
988
+ };
989
+ readonly cancelAtPeriodEnd: {
990
+ readonly type: "boolean";
991
+ readonly defaultValue: false;
992
+ };
993
+ readonly cancelAt: {
994
+ readonly type: "date";
995
+ };
996
+ readonly canceledAt: {
997
+ readonly type: "date";
998
+ };
999
+ readonly endedAt: {
1000
+ readonly type: "date";
1001
+ };
1002
+ readonly seats: {
1003
+ readonly type: "number";
1004
+ };
1005
+ readonly billingInterval: {
1006
+ readonly type: "string";
1007
+ };
1008
+ readonly stripeScheduleId: {
1009
+ readonly type: "string";
1010
+ };
1011
+ };
1012
+ };
1013
+ };
1014
+ };
1015
+ readonly twoFactor: {
1016
+ readonly fields: {
1017
+ readonly user: {
1018
+ readonly twoFactorEnabled: {
1019
+ readonly type: "boolean";
1020
+ readonly defaultValue: false;
1021
+ };
1022
+ };
1023
+ };
1024
+ readonly tables: {
1025
+ readonly twoFactor: {
1026
+ readonly fields: {
1027
+ readonly secret: {
1028
+ readonly type: "string";
1029
+ readonly required: true;
1030
+ readonly index: true;
1031
+ };
1032
+ readonly backupCodes: {
1033
+ readonly type: "string";
1034
+ readonly required: true;
1035
+ };
1036
+ readonly userId: {
1037
+ readonly type: "string";
1038
+ readonly required: true;
1039
+ readonly index: true;
1040
+ readonly references: {
1041
+ readonly model: "user";
1042
+ readonly field: "id";
1043
+ readonly onDelete: "cascade";
1044
+ };
1045
+ };
1046
+ readonly verified: {
1047
+ readonly type: "boolean";
1048
+ readonly defaultValue: true;
1049
+ };
1050
+ readonly failedVerificationCount: {
1051
+ readonly type: "number";
1052
+ readonly defaultValue: 0;
1053
+ };
1054
+ readonly lockedUntil: {
1055
+ readonly type: "date";
1056
+ };
1057
+ };
1058
+ };
1059
+ };
1060
+ };
1061
+ readonly username: {
1062
+ readonly fields: {
1063
+ readonly user: {
1064
+ readonly username: {
1065
+ readonly type: "string";
1066
+ readonly unique: true;
1067
+ };
1068
+ readonly displayUsername: {
1069
+ readonly type: "string";
1070
+ };
1071
+ };
1072
+ };
1073
+ };
1074
+ };
1075
+ /** The literal type of `authPluginSchemas`, which types the plugin tables and columns. */
1076
+ type AuthPluginSchemas = typeof pluginSchemas;
823
1077
  /**
824
1078
  * The tables and columns of each plugin of `AuthSchemaPlugin`, with all of its options on: a column or table that the
825
1079
  * options turn off stays empty. A test checks the plugins of `better-auth/plugins` against Better Auth's own
@@ -839,4 +1093,4 @@ interface AuthSchemaOptions {
839
1093
  */
840
1094
  declare function resolveAuthTableSpecs(options?: AuthSchemaOptions): Record<string, AuthTableSpec>;
841
1095
  //#endregion
842
- export { AuthTableField as a, authPluginSchemas as c, AuthSchemaPlugin as i, authTableSpecs as l, AuthCoreTableSpecs as n, AuthTableName as o, AuthSchemaOptions as r, AuthTableSpec as s, AuthCoreModel as t, resolveAuthTableSpecs as u };
1096
+ export { AuthSchemaPlugin as a, AuthTableSpec as c, resolveAuthTableSpecs as d, AuthSchemaOptions as i, authPluginSchemas as l, AuthCoreTableSpecs as n, AuthTableField as o, AuthPluginSchemas as r, AuthTableName as s, AuthCoreModel as t, authTableSpecs as u };
@@ -1,17 +1,4 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-Dymr-S_n.js";
2
- //#region src/table-specs.ts
3
- const requiredString = {
4
- type: "string",
5
- required: true
6
- };
7
- const optionalString = { type: "string" };
8
- const optionalDate = { type: "date" };
9
- const optionalBoolean = { type: "boolean" };
10
- const userReference = {
11
- model: "user",
12
- field: "id",
13
- onDelete: "cascade"
14
- };
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-uEbxSY2G.js";
15
2
  /**
16
3
  * The Better Auth core tables, with the fields of the plugins that ViteHub ships: `admin()` (`user.role`, bans, and
17
4
  * `session.impersonatedBy`), the `jwt()` and `oauthProvider()` tables of `mcpOAuth()`, the tables of
@@ -599,14 +586,14 @@ const authPluginSchemas = {
599
586
  index: true,
600
587
  defaultValue: "default"
601
588
  },
602
- name: optionalString,
603
- start: optionalString,
589
+ name: { type: "string" },
590
+ start: { type: "string" },
604
591
  referenceId: {
605
592
  type: "string",
606
593
  required: true,
607
594
  index: true
608
595
  },
609
- prefix: optionalString,
596
+ prefix: { type: "string" },
610
597
  key: {
611
598
  type: "string",
612
599
  required: true,
@@ -617,7 +604,7 @@ const authPluginSchemas = {
617
604
  bigint: true
618
605
  },
619
606
  refillAmount: { type: "number" },
620
- lastRefillAt: optionalDate,
607
+ lastRefillAt: { type: "date" },
621
608
  enabled: {
622
609
  type: "boolean",
623
610
  defaultValue: true
@@ -640,8 +627,8 @@ const authPluginSchemas = {
640
627
  defaultValue: 0
641
628
  },
642
629
  remaining: { type: "number" },
643
- lastRequest: optionalDate,
644
- expiresAt: optionalDate,
630
+ lastRequest: { type: "date" },
631
+ expiresAt: { type: "date" },
645
632
  createdAt: {
646
633
  type: "date",
647
634
  required: true
@@ -650,45 +637,51 @@ const authPluginSchemas = {
650
637
  type: "date",
651
638
  required: true
652
639
  },
653
- permissions: optionalString,
654
- metadata: optionalString
640
+ permissions: { type: "string" },
641
+ metadata: { type: "string" }
655
642
  } } } },
656
- lastLoginMethod: { fields: { user: { lastLoginMethod: optionalString } } },
643
+ lastLoginMethod: { fields: { user: { lastLoginMethod: { type: "string" } } } },
657
644
  phoneNumber: { fields: { user: {
658
645
  phoneNumber: {
659
646
  type: "string",
660
647
  unique: true
661
648
  },
662
- phoneNumberVerified: optionalBoolean
649
+ phoneNumberVerified: { type: "boolean" }
663
650
  } } },
664
651
  stripe: {
665
652
  fields: {
666
- user: { stripeCustomerId: optionalString },
667
- organization: { stripeCustomerId: optionalString }
653
+ user: { stripeCustomerId: { type: "string" } },
654
+ organization: { stripeCustomerId: { type: "string" } }
668
655
  },
669
656
  tables: { subscription: { fields: {
670
- plan: requiredString,
671
- referenceId: requiredString,
672
- stripeCustomerId: optionalString,
673
- stripeSubscriptionId: optionalString,
657
+ plan: {
658
+ type: "string",
659
+ required: true
660
+ },
661
+ referenceId: {
662
+ type: "string",
663
+ required: true
664
+ },
665
+ stripeCustomerId: { type: "string" },
666
+ stripeSubscriptionId: { type: "string" },
674
667
  status: {
675
668
  type: "string",
676
669
  defaultValue: "incomplete"
677
670
  },
678
- periodStart: optionalDate,
679
- periodEnd: optionalDate,
680
- trialStart: optionalDate,
681
- trialEnd: optionalDate,
671
+ periodStart: { type: "date" },
672
+ periodEnd: { type: "date" },
673
+ trialStart: { type: "date" },
674
+ trialEnd: { type: "date" },
682
675
  cancelAtPeriodEnd: {
683
676
  type: "boolean",
684
677
  defaultValue: false
685
678
  },
686
- cancelAt: optionalDate,
687
- canceledAt: optionalDate,
688
- endedAt: optionalDate,
679
+ cancelAt: { type: "date" },
680
+ canceledAt: { type: "date" },
681
+ endedAt: { type: "date" },
689
682
  seats: { type: "number" },
690
- billingInterval: optionalString,
691
- stripeScheduleId: optionalString
683
+ billingInterval: { type: "string" },
684
+ stripeScheduleId: { type: "string" }
692
685
  } } }
693
686
  },
694
687
  twoFactor: {
@@ -702,12 +695,19 @@ const authPluginSchemas = {
702
695
  required: true,
703
696
  index: true
704
697
  },
705
- backupCodes: requiredString,
698
+ backupCodes: {
699
+ type: "string",
700
+ required: true
701
+ },
706
702
  userId: {
707
703
  type: "string",
708
704
  required: true,
709
705
  index: true,
710
- references: userReference
706
+ references: {
707
+ model: "user",
708
+ field: "id",
709
+ onDelete: "cascade"
710
+ }
711
711
  },
712
712
  verified: {
713
713
  type: "boolean",
@@ -717,7 +717,7 @@ const authPluginSchemas = {
717
717
  type: "number",
718
718
  defaultValue: 0
719
719
  },
720
- lockedUntil: optionalDate
720
+ lockedUntil: { type: "date" }
721
721
  } } }
722
722
  },
723
723
  username: { fields: { user: {
@@ -725,7 +725,7 @@ const authPluginSchemas = {
725
725
  type: "string",
726
726
  unique: true
727
727
  },
728
- displayUsername: optionalString
728
+ displayUsername: { type: "string" }
729
729
  } } }
730
730
  };
731
731
  function sameField(left, right) {
package/dist/test.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { g as AuthDefinition } from "./types-CruflEFI.js";
1
+ import { _ as AuthDefinition } from "./types-gl-myjZc.js";
2
2
  import { Session, User } from "better-auth";
3
3
  //#region src/test.d.ts
4
4
  /** The user to sign in. Auth creates it when no user has this email. Other fields, such as `role`, go to the new user. */
package/dist/test.js CHANGED
@@ -1,5 +1,5 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-Dymr-S_n.js";
2
- import { o as resolveDefaultDefinition, t as authForRequest } from "./auth-instance-CmDogt4D.js";
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-uEbxSY2G.js";
2
+ import { s as resolveDefaultDefinition, t as authForRequest } from "./auth-instance-zYMjldPG.js";
3
3
  import { testUtils } from "better-auth/plugins";
4
4
  //#region src/test.ts
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { t as AuthPreset } from "./presets-CHndEv5i.js";
2
- import { r as AuthSchemaOptions } from "./table-specs-DbXyaXWs.js";
2
+ import { i as AuthSchemaOptions } from "./table-specs-BhWz_U0M.js";
3
3
  import { AccessAuthorizationContext, AccessAuthorize, AccessAuthorizeResult, AnonymousAccessAuthorizationContext, AnonymousAccessAuthorize, Duration } from "@vite-hub/runtime";
4
4
  import { ViteHubContext as ViteHubContext$1 } from "@vite-hub/runtime/internal/h3";
5
5
  import { Auth, BetterAuthOptions, DBAdapter, Session, User } from "better-auth";
@@ -87,6 +87,25 @@ declare function createDatabaseAuthEventStore(options: {
87
87
  retention?: AuthEventRetention | false;
88
88
  }): AuthEventStore;
89
89
  //#endregion
90
+ //#region src/nuxt-types.d.ts
91
+ /** Who may open a page: signed-in users (`user`) or signed-out visitors (`guest`). */
92
+ type AuthPageMode = "guest" | "user";
93
+ /**
94
+ * The `auth` key of `definePageMeta()` in Nuxt. `'user'` or `true` sends visitors without a session to the login
95
+ * page. `'guest'` sends signed-in users away, for example from the login page. `false` turns the guard off.
96
+ */
97
+ type AuthPageMeta = boolean | AuthPageMode | {
98
+ only?: AuthPageMode;
99
+ /** Where to send the visitor instead of the configured redirect. */
100
+ redirectTo?: string;
101
+ };
102
+ /**
103
+ * `access.pages`: the Nuxt pages that the page guard protects, by route pattern, such as `'/dashboard/**'`. A key has
104
+ * static segments, `:name`, and a last `**`. `'user'` and `'guest'` work as in `definePageMeta({ auth })`. `false`
105
+ * removes the guard of a wider pattern from the matching pages.
106
+ */
107
+ type AuthPages = Record<`/${string}`, AuthPageMode | false>;
108
+ //#endregion
90
109
  //#region src/console-types.d.ts
91
110
  type AuthConsoleValue = string | number | boolean | null | string[] | number[];
92
111
  type AuthConsoleFieldType = "string" | "number" | "boolean" | "date" | "string[]" | "number[]" | "json";
@@ -279,6 +298,7 @@ interface AuthConsoleHostUserInput {
279
298
  /** A live session of a user that holds a host role, with the user's roles. */
280
299
  interface AuthConsoleHostSession extends AuthConsoleSession {
281
300
  roles: string[];
301
+ guest: boolean;
282
302
  }
283
303
  interface AuthConsoleAgent {
284
304
  id: string;
@@ -373,7 +393,7 @@ declare global {
373
393
  }
374
394
  }
375
395
  type AuthRuntimeOption = "baseURL" | "secret" | "secrets";
376
- type AuthReservedOption = AuthRuntimeOption | "events" | "console" | "access" | "adminClaim" | "basePath" | "database" | "deleteAccount" | "preset" | "route" | "runtime" | "secondaryStorage";
396
+ type AuthReservedOption = AuthRuntimeOption | "events" | "console" | "access" | "adminClaim" | "basePath" | "components" | "database" | "deleteAccount" | "preset" | "route" | "runtime" | "secondaryStorage";
377
397
  type AuthBetterAuthOptions = Omit<BetterAuthOptions, AuthReservedOption | "session"> & {
378
398
  session?: AuthSessionOptions;
379
399
  };
@@ -486,11 +506,22 @@ interface AuthAccessConfiguration {
486
506
  * user from an `auth: 'guest'` page. Default: `"/"`.
487
507
  */
488
508
  afterSignIn?: string;
509
+ /**
510
+ * Nuxt pages that the page guard protects, by route pattern: `'user'`, `'guest'`, or `false`, such as
511
+ * `{ '/dashboard/**': 'user', '/login': 'guest' }`. The most specific pattern wins, and `definePageMeta({ auth })` of
512
+ * a page wins over all patterns. Vite apps without Nuxt ignore it.
513
+ */
514
+ pages?: AuthPages;
489
515
  }
490
516
  /** The Better Auth adapter of `authDatabase()`. `vitehubDatabase` names the app Database that holds the Auth tables. */
491
517
  type AuthAppDatabase = ((options: BetterAuthOptions) => DBAdapter<BetterAuthOptions>) & {
492
518
  readonly vitehubDatabase: string;
493
519
  };
520
+ /** `components` of `defineAuth()`: how the Nuxt module names the Auth components. */
521
+ interface AuthComponentsOptions {
522
+ /** Prepended to each component name, such as `"Custom"` for `<CustomAuthPermission>`. */
523
+ prefix?: string;
524
+ }
494
525
  interface AuthViteHubOptions {
495
526
  /** Ignore `VITEHUB_ADMIN_CLAIM` for this Auth Definition. Independent Console Auth sets this to `false`. */
496
527
  adminClaim?: false;
@@ -505,6 +536,16 @@ interface AuthViteHubOptions {
505
536
  console?: AuthConsoleOptions;
506
537
  access?: AuthAccessConfiguration;
507
538
  basePath?: string;
539
+ /**
540
+ * The names that the Nuxt module gives `<AuthPermission>`. A prefix keeps it apart from an app component of the same name.
541
+ * The prefix follows Nuxt's component prefix rules, as the prefix of `components: [{ path, prefix }]` does: words that the
542
+ * name starts with are dropped, so `MyAuth` gives `<MyAuthPermission>` and `Auth` changes nothing. The Vite
543
+ * plugin reads it at build time, so write it as an inline string literal. The module registers `<AuthPermission>` only
544
+ * when the app has `shared/abilities.ts`. Vite apps without Nuxt ignore it.
545
+ *
546
+ * @example { prefix: "Custom" } // <CustomAuthPermission>
547
+ */
548
+ components?: AuthComponentsOptions;
508
549
  /**
509
550
  * `authDatabase()` from `vite-hub/auth/database` keeps users and sessions in the app Database. Return another Better
510
551
  * Auth adapter from the Definition callback. `"memory"` keeps them in the memory of one server process,
@@ -552,8 +593,14 @@ interface ResolvedAuthViteConfig {
552
593
  };
553
594
  /** `access.afterSignIn`. Set only when the Definition has it. */
554
595
  afterSignIn?: string;
596
+ /** `access.pages`. Set only when the Definition has it. */
597
+ pages?: AuthPages;
555
598
  };
556
599
  basePath: string;
600
+ /** `components` of the Definition, which the Nuxt module reads at build time. Set only when the Definition has a prefix. */
601
+ components?: {
602
+ prefix: string;
603
+ };
557
604
  /**
558
605
  * The app Database that `authDatabase()` names, which gets the Better Auth tables, and the plugins and additional fields
559
606
  * of the Definition that add tables and columns. `false` without the call.
@@ -568,7 +615,7 @@ interface ResolvedAuthViteConfig {
568
615
  rootDir: string;
569
616
  route: false | string;
570
617
  }
571
- type AuthBetterAuthRuntimeOptions<TOptions extends AuthDefinitionInput = AuthDefinitionInput> = (TOptions extends AuthDefinitionResolver<infer TResolved> ? Omit<TResolved, AuthRuntimeOption | "events" | "console" | "access" | "adminClaim" | "database" | "deleteAccount" | "preset" | "route" | "runtime" | "secondaryStorage"> : Omit<TOptions, AuthRuntimeOption | "events" | "console" | "access" | "adminClaim" | "database" | "deleteAccount" | "preset" | "route" | "runtime" | "secondaryStorage">) & AuthRuntimeOptions & BetterAuthOptions;
618
+ type AuthBetterAuthRuntimeOptions<TOptions extends AuthDefinitionInput = AuthDefinitionInput> = (TOptions extends AuthDefinitionResolver<infer TResolved> ? Omit<TResolved, AuthRuntimeOption | "events" | "console" | "access" | "adminClaim" | "components" | "database" | "deleteAccount" | "preset" | "route" | "runtime" | "secondaryStorage"> : Omit<TOptions, AuthRuntimeOption | "events" | "console" | "access" | "adminClaim" | "components" | "database" | "deleteAccount" | "preset" | "route" | "runtime" | "secondaryStorage">) & AuthRuntimeOptions & BetterAuthOptions;
572
619
  type AuthRequest = Pick<Request, "body" | "headers" | "method" | "signal" | "url">;
573
620
  /**
574
621
  * A Web Request, or a request event with Standard Context properties, such as an H3 2 event in a ViteHub app.
@@ -585,4 +632,4 @@ type RegisteredAuth<TRegistry = ViteHub.AuthRegistry> = TRegistry extends {
585
632
  /** `false` turns Auth off. `server/auth.ts` turns it on, and `defineAuth()` holds every Auth option. */
586
633
  type AuthOptions = false;
587
634
  //#endregion
588
- export { AuthConsoleEventUser as $, AuthRuntimeOnlyOptions as A, AuthEventMetadata as At, RegisteredAuth as B, AuthOptions as C, authConsoleEventGroups as Ct, AuthResolvedDefinitionOptions as D, AuthEventAggregates as Dt, AuthReservedOption as E, AuthEventActor as Et, AuthSessionRefreshContext as F, AuthEventWindow as Ft, AuthConsoleActivity as G, ResolvedAuthViteConfig as H, AuthSessionRefreshFields as I, AuthEventsConfiguration as It, AuthConsoleCapability as J, AuthConsoleActivityQuery as K, AuthSignInConfiguration as L, createDatabaseAuthEventStore as Lt, AuthRuntimeOptions as M, AuthEventRetention as Mt, AuthSessionOptions as N, AuthEventStore as Nt, AuthRuntimeContext as O, AuthEventCounts as Ot, AuthSessionRefresh as P, AuthEventType as Pt, AuthConsoleEventGroup as Q, AuthViteHubOptions as R, defaultAuthEventRetention as Rt, AuthGuardedHandler as S, authConsoleActionNames as St, AuthRequestInput as T, AuthEvent as Tt, ViteHubAuth as U, ResolvedAuthAccessRoute as V, AuthConsoleAction as W, AuthConsoleDescription as X, AuthConsoleColumn as Y, AuthConsoleEvent as Z, AuthDefinitionInput as _, AuthConsoleSession as _t, AuthAccessPolicy as a, AuthConsoleHostUserInput as at, AuthDeleteAccountOptions as b, AuthConsoleUserDetail as bt, AuthAccessRouteConfiguration as c, AuthConsoleMutation as ct, AuthAnonymousGuardedHandler as d, AuthConsoleOrganizationDetail as dt, AuthConsoleField as et, AuthAppDatabase as f, AuthConsoleOverview as ft, AuthDefinition as g, AuthConsoleRoles as gt, AuthBetterAuthRuntimeOptions as h, AuthConsoleQuery as ht, AuthAccessConfiguration as i, AuthConsoleHostSession as it, AuthRuntimeOption as j, AuthEventPage as jt, AuthRuntimeEnv as k, AuthEventListInput as kt, AuthAnonymousAuthorization as l, AuthConsoleOptions as lt, AuthBetterAuthOptions as m, AuthConsolePolicy as mt, AuthAccessAuthorize as n, AuthConsoleFieldType as nt, AuthAccessPolicyContext as o, AuthConsoleImpersonation as ot, AuthAuthorization as p, AuthConsolePage as pt, AuthConsoleAgent as q, AuthAccessAuthorizeResult as r, AuthConsoleHostOptions as rt, AuthAccessRoute as s, AuthConsoleList as st, AuthAccessAuthorizationContext as t, AuthConsoleFieldPolicy as tt, AuthAnonymousAuthorize as u, AuthConsoleOrganization as ut, AuthDefinitionOptions as v, AuthConsoleSessionUser as vt, AuthRequest as w, AuthDevice as wt, AuthFor as x, AuthConsoleValue as xt, AuthDefinitionResolver as y, AuthConsoleUser as yt, DiscoveredAuthDefinition as z };
635
+ export { AuthConsoleEventGroup as $, AuthRuntimeEnv as A, AuthEventActor as At, DiscoveredAuthDefinition as B, AuthEventsConfiguration as Bt, AuthGuardedHandler as C, authConsoleActionNames as Ct, AuthReservedOption as D, AuthPages as Dt, AuthRequestInput as E, AuthPageMode as Et, AuthSessionRefresh as F, AuthEventPage as Ft, AuthConsoleAction as G, ResolvedAuthAccessRoute as H, defaultAuthEventRetention as Ht, AuthSessionRefreshContext as I, AuthEventRetention as It, AuthConsoleAgent as J, AuthConsoleActivity as K, AuthSessionRefreshFields as L, AuthEventStore as Lt, AuthRuntimeOption as M, AuthEventCounts as Mt, AuthRuntimeOptions as N, AuthEventListInput as Nt, AuthResolvedDefinitionOptions as O, AuthDevice as Ot, AuthSessionOptions as P, AuthEventMetadata as Pt, AuthConsoleEvent as Q, AuthSignInConfiguration as R, AuthEventType as Rt, AuthFor as S, AuthConsoleValue as St, AuthRequest as T, AuthPageMeta as Tt, ResolvedAuthViteConfig as U, RegisteredAuth as V, createDatabaseAuthEventStore as Vt, ViteHubAuth as W, AuthConsoleColumn as X, AuthConsoleCapability as Y, AuthConsoleDescription as Z, AuthDefinition as _, AuthConsoleRoles as _t, AuthAccessPolicy as a, AuthConsoleHostSession as at, AuthDefinitionResolver as b, AuthConsoleUser as bt, AuthAccessRouteConfiguration as c, AuthConsoleList as ct, AuthAnonymousGuardedHandler as d, AuthConsoleOrganization as dt, AuthConsoleEventUser as et, AuthAppDatabase as f, AuthConsoleOrganizationDetail as ft, AuthComponentsOptions as g, AuthConsoleQuery as gt, AuthBetterAuthRuntimeOptions as h, AuthConsolePolicy as ht, AuthAccessConfiguration as i, AuthConsoleHostOptions as it, AuthRuntimeOnlyOptions as j, AuthEventAggregates as jt, AuthRuntimeContext as k, AuthEvent as kt, AuthAnonymousAuthorization as l, AuthConsoleMutation as lt, AuthBetterAuthOptions as m, AuthConsolePage as mt, AuthAccessAuthorize as n, AuthConsoleFieldPolicy as nt, AuthAccessPolicyContext as o, AuthConsoleHostUserInput as ot, AuthAuthorization as p, AuthConsoleOverview as pt, AuthConsoleActivityQuery as q, AuthAccessAuthorizeResult as r, AuthConsoleFieldType as rt, AuthAccessRoute as s, AuthConsoleImpersonation as st, AuthAccessAuthorizationContext as t, AuthConsoleField as tt, AuthAnonymousAuthorize as u, AuthConsoleOptions as ut, AuthDefinitionInput as v, AuthConsoleSession as vt, AuthOptions as w, authConsoleEventGroups as wt, AuthDeleteAccountOptions as x, AuthConsoleUserDetail as xt, AuthDefinitionOptions as y, AuthConsoleSessionUser as yt, AuthViteHubOptions as z, AuthEventWindow as zt };