@commonpub/layer 0.8.6 → 0.8.7

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.7",
4
4
  "type": "module",
5
5
  "main": "./nuxt.config.ts",
6
6
  "files": [
@@ -53,12 +53,12 @@
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
- "@commonpub/config": "0.9.1",
59
- "@commonpub/editor": "0.7.9",
60
57
  "@commonpub/learning": "0.5.0",
58
+ "@commonpub/editor": "0.7.9",
59
+ "@commonpub/auth": "0.5.1",
61
60
  "@commonpub/protocol": "0.9.9",
61
+ "@commonpub/config": "0.9.1",
62
62
  "@commonpub/ui": "0.8.5"
63
63
  },
64
64
  "devDependencies": {
@@ -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 } }>(