@commonpub/layer 0.8.6 → 0.8.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonpub/layer",
3
- "version": "0.8.6",
3
+ "version": "0.8.8",
4
4
  "type": "module",
5
5
  "main": "./nuxt.config.ts",
6
6
  "files": [
@@ -53,13 +53,13 @@
53
53
  "vue": "^3.4.0",
54
54
  "vue-router": "^4.3.0",
55
55
  "zod": "^4.3.6",
56
- "@commonpub/auth": "0.5.1",
57
56
  "@commonpub/docs": "0.6.2",
58
57
  "@commonpub/config": "0.9.1",
59
58
  "@commonpub/editor": "0.7.9",
60
59
  "@commonpub/learning": "0.5.0",
61
- "@commonpub/protocol": "0.9.9",
62
- "@commonpub/ui": "0.8.5"
60
+ "@commonpub/auth": "0.5.1",
61
+ "@commonpub/ui": "0.8.5",
62
+ "@commonpub/protocol": "0.9.9"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@testing-library/jest-dom": "^6.9.1",
@@ -1,4 +1,6 @@
1
1
  import { linkFederatedAccount, consumePendingLink } from '@commonpub/server';
2
+ import { eq, and, isNull } from 'drizzle-orm';
3
+ import { users } from '@commonpub/schema';
2
4
  import { z } from 'zod';
3
5
 
4
6
  const linkSchema = z.object({
@@ -30,12 +32,18 @@ export default defineEventHandler(async (event) => {
30
32
  }
31
33
 
32
34
  // Step 2: Resolve identity to email
33
- const { email } = await $fetch<{ email: string }>('/api/resolve-identity', {
34
- method: 'POST',
35
- body: { identity: body.identity },
36
- }).catch(() => {
37
- throw createError({ statusCode: 401, statusMessage: 'Invalid credentials.' });
38
- });
35
+ let email = body.identity;
36
+ if (!body.identity.includes('@')) {
37
+ const [user] = await db
38
+ .select({ email: users.email })
39
+ .from(users)
40
+ .where(and(eq(users.username, body.identity), isNull(users.deletedAt)))
41
+ .limit(1);
42
+ if (!user) {
43
+ throw createError({ statusCode: 401, statusMessage: 'Invalid credentials.' });
44
+ }
45
+ email = user.email;
46
+ }
39
47
 
40
48
  // Step 3: Authenticate via Better Auth sign-in (also creates session + sets cookie)
41
49
  const signInResponse = await $fetch<{ user?: { id: string }; session?: { token: string; expiresAt: string } }>(
@@ -110,10 +110,13 @@ export default defineEventHandler(async (event) => {
110
110
  return;
111
111
  }
112
112
 
113
- // Handle auth API routes — skip our custom federated/oauth2 routes (Nitro handles those)
114
- const isBetterAuthRoute = pathname.startsWith('/api/auth')
115
- && !pathname.startsWith('/api/auth/federated/')
116
- && !pathname.startsWith('/api/auth/oauth2/');
113
+ // Handle auth API routes — skip custom routes that Nitro handles directly
114
+ const isCustomAuthRoute = pathname.startsWith('/api/auth/federated/')
115
+ || pathname.startsWith('/api/auth/oauth2/')
116
+ || pathname === '/api/auth/sign-in-username'
117
+ || pathname === '/api/auth/delete-user'
118
+ || pathname === '/api/auth/export-data';
119
+ const isBetterAuthRoute = pathname.startsWith('/api/auth') && !isCustomAuthRoute;
117
120
 
118
121
  if (isBetterAuthRoute) {
119
122
  try {