better-auth-studio 1.0.79-beta.36 → 1.0.79-beta.38

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.
@@ -5,7 +5,7 @@
5
5
  <link rel="icon" type="image/png" href="/logo.png" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>Better Auth Studio</title>
8
- <script type="module" crossorigin src="/assets/main-BxLtFscV.js"></script>
8
+ <script type="module" crossorigin src="/assets/main-DEnyGsn2.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/assets/main-BgI41EAt.css">
10
10
  </head>
11
11
  <body>
@@ -1 +1 @@
1
- {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAeA,OAAO,EAA+B,MAAM,EAAE,MAAM,SAAS,CAAC;AAU9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAK9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AA0GnE,wBAAsB,oBAAoB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAqLhG;AAeD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,EAClB,gBAAgB,CAAC,EAAE,GAAG,EACtB,oBAAoB,CAAC,EAAE,GAAG,EAC1B,YAAY,CAAC,EAAE,kBAAkB,EACjC,YAAY,CAAC,EAAE,GAAG,GACjB,MAAM,CAkxMR;AAED,wBAAsB,sBAAsB,CAAC,GAAG,EAAE;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,IAAI,EAAE,GAAG,CAAC;IAC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MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,kBAAkB,CAAC;CACnC,GAAG,OAAO,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,GAAG,CAAC;IACV,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,CAAC,CAAC;CAChE,CAAC,CA+FD"}
package/dist/routes.js CHANGED
@@ -2721,6 +2721,26 @@ export function createRoutes(authConfig, configPath, geoDbPath, preloadedAdapter
2721
2721
  if (!adapter.update) {
2722
2722
  return res.status(500).json({ error: 'Adapter update method not available' });
2723
2723
  }
2724
+ let invitation = null;
2725
+ try {
2726
+ invitation = await adapter.findOne({
2727
+ model: 'invitation',
2728
+ where: [{ field: 'id', value: id }],
2729
+ });
2730
+ }
2731
+ catch (_findError) {
2732
+ if (typeof adapter.findMany === 'function') {
2733
+ const invitations = await adapter.findMany({
2734
+ model: 'invitation',
2735
+ where: [{ field: 'id', value: id }],
2736
+ limit: 1,
2737
+ });
2738
+ invitation = invitations && invitations.length > 0 ? invitations[0] : null;
2739
+ }
2740
+ }
2741
+ if (!invitation) {
2742
+ return res.status(404).json({ error: 'Invitation not found' });
2743
+ }
2724
2744
  await adapter.update({
2725
2745
  model: 'invitation',
2726
2746
  where: [{ field: 'id', value: id }],
@@ -2731,8 +2751,13 @@ export function createRoutes(authConfig, configPath, geoDbPath, preloadedAdapter
2731
2751
  });
2732
2752
  res.json({ success: true });
2733
2753
  }
2734
- catch (_error) {
2735
- res.status(500).json({ error: 'Failed to resend invitation' });
2754
+ catch (error) {
2755
+ console.error('Error resending invitation:', error);
2756
+ const errorMessage = error instanceof Error ? error.message : 'Failed to resend invitation';
2757
+ res.status(500).json({
2758
+ error: 'Failed to resend invitation',
2759
+ details: isSelfHosted ? errorMessage : undefined,
2760
+ });
2736
2761
  }
2737
2762
  });
2738
2763
  router.get('/api/users/:userId/invitations', async (req, res) => {
@@ -2994,7 +3019,13 @@ export function createRoutes(authConfig, configPath, geoDbPath, preloadedAdapter
2994
3019
  router.post('/api/organizations/:orgId/invitations', async (req, res) => {
2995
3020
  try {
2996
3021
  const { orgId } = req.params;
2997
- const { email, role = 'member', inviterId } = req.body;
3022
+ const { email, role = 'member', inviterId, teamId } = req.body;
3023
+ if (!email || typeof email !== 'string') {
3024
+ return res.status(400).json({ error: 'Email is required' });
3025
+ }
3026
+ if (!orgId) {
3027
+ return res.status(400).json({ error: 'Organization ID is required' });
3028
+ }
2998
3029
  if (!inviterId) {
2999
3030
  return res.status(400).json({ error: 'Inviter ID is required' });
3000
3031
  }
@@ -3002,38 +3033,91 @@ export function createRoutes(authConfig, configPath, geoDbPath, preloadedAdapter
3002
3033
  if (!adapter) {
3003
3034
  return res.status(500).json({ error: 'Auth adapter not available' });
3004
3035
  }
3036
+ if (!adapter.create) {
3037
+ return res.status(500).json({ error: 'Adapter create method not available' });
3038
+ }
3039
+ try {
3040
+ const organization = await adapter.findOne({
3041
+ model: 'organization',
3042
+ where: [{ field: 'id', value: orgId }],
3043
+ });
3044
+ if (!organization) {
3045
+ return res.status(404).json({ error: 'Organization not found' });
3046
+ }
3047
+ }
3048
+ catch (orgError) {
3049
+ try {
3050
+ if (typeof adapter.findMany === 'function') {
3051
+ const orgs = await adapter.findMany({
3052
+ model: 'organization',
3053
+ where: [{ field: 'id', value: orgId }],
3054
+ limit: 1,
3055
+ });
3056
+ if (!orgs || orgs.length === 0) {
3057
+ return res.status(404).json({ error: 'Organization not found' });
3058
+ }
3059
+ }
3060
+ }
3061
+ catch (_fallbackError) { }
3062
+ }
3063
+ try {
3064
+ let existingInvitation = null;
3065
+ if (typeof adapter.findFirst === 'function') {
3066
+ existingInvitation = await adapter.findFirst({
3067
+ model: 'invitation',
3068
+ where: [
3069
+ { field: 'email', value: email.toLowerCase() },
3070
+ { field: 'organizationId', value: orgId },
3071
+ { field: 'status', value: 'pending' },
3072
+ ],
3073
+ });
3074
+ }
3075
+ else if (typeof adapter.findMany === 'function') {
3076
+ const invitations = await adapter.findMany({
3077
+ model: 'invitation',
3078
+ where: [
3079
+ { field: 'email', value: email.toLowerCase() },
3080
+ { field: 'organizationId', value: orgId },
3081
+ { field: 'status', value: 'pending' },
3082
+ ],
3083
+ limit: 1,
3084
+ });
3085
+ existingInvitation = invitations && invitations.length > 0 ? invitations[0] : null;
3086
+ }
3087
+ if (existingInvitation) {
3088
+ return res
3089
+ .status(400)
3090
+ .json({ error: 'A pending invitation already exists for this email' });
3091
+ }
3092
+ }
3093
+ catch (_duplicateCheckError) { }
3005
3094
  const invitationData = {
3006
- email,
3095
+ email: email.toLowerCase(),
3007
3096
  role,
3008
3097
  organizationId: orgId,
3009
3098
  status: 'pending',
3010
3099
  expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), // 7 days
3011
- createdAt: new Date(),
3012
3100
  inviterId: inviterId,
3013
3101
  };
3014
- const invitation = {
3015
- id: `inv_${Date.now()}`,
3016
- ...invitationData,
3017
- };
3018
- if (!adapter.create) {
3019
- return res.status(500).json({ error: 'Adapter create method not available' });
3102
+ if (teamId) {
3103
+ invitationData.teamId = teamId;
3020
3104
  }
3021
- await adapter.create({
3105
+ const createdInvitation = await adapter.create({
3022
3106
  model: 'invitation',
3023
- data: {
3024
- organizationId: invitationData.organizationId,
3025
- email: invitationData.email,
3026
- role: invitationData.role,
3027
- status: invitationData.status,
3028
- inviterId: invitationData.inviterId,
3029
- expiresAt: invitationData.expiresAt,
3030
- createdAt: invitationData.createdAt,
3031
- },
3107
+ data: invitationData,
3032
3108
  });
3033
- res.json({ success: true, invitation });
3109
+ if (!createdInvitation) {
3110
+ return res.status(500).json({ error: 'Failed to create invitation' });
3111
+ }
3112
+ res.json({ success: true, invitation: createdInvitation });
3034
3113
  }
3035
- catch (_error) {
3036
- res.status(500).json({ error: 'Failed to create invitation' });
3114
+ catch (error) {
3115
+ console.error('Error creating invitation:', error);
3116
+ const errorMessage = error instanceof Error ? error.message : 'Failed to create invitation';
3117
+ res.status(500).json({
3118
+ error: 'Failed to create invitation',
3119
+ details: isSelfHosted ? errorMessage : undefined,
3120
+ });
3037
3121
  }
3038
3122
  });
3039
3123
  router.get('/api/organizations/:orgId/teams', async (req, res) => {