@momentumcms/auth 0.5.6 → 0.5.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/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 0.5.7 (2026-03-10)
2
+
3
+ ### 🩹 Fixes
4
+
5
+ - migration mode fixes, first-user admin, and overrideAccess bypass ([bf164074](https://github.com/DonaldMurillo/momentum-cms/commit/bf164074))
6
+
7
+ ### ❤️ Thank You
8
+
9
+ - Claude Opus 4.6
10
+ - Donald Murillo @DonaldMurillo
11
+
1
12
  ## 0.5.6 (2026-03-10)
2
13
 
3
14
  This was a version bump only for auth to align it with other projects, there were no code changes.
package/index.cjs CHANGED
@@ -1815,8 +1815,32 @@ function createMomentumAuth(config) {
1815
1815
  plugins.push(p);
1816
1816
  }
1817
1817
  }
1818
+ const firstUserAdminHook = {
1819
+ user: {
1820
+ create: {
1821
+ async before(user) {
1822
+ try {
1823
+ let count = 0;
1824
+ if (dbConfig.type === "sqlite") {
1825
+ const row2 = dbConfig.database.prepare('SELECT COUNT(*) as cnt FROM "user"').get();
1826
+ count = row2 && typeof row2 === "object" && "cnt" in row2 ? Number(row2.cnt) : 0;
1827
+ } else {
1828
+ const result = await dbConfig.pool.query('SELECT COUNT(*) as cnt FROM "user"');
1829
+ count = Number(result.rows[0]?.cnt ?? 0);
1830
+ }
1831
+ if (count === 0) {
1832
+ return { data: { ...user, role: "admin" } };
1833
+ }
1834
+ } catch {
1835
+ }
1836
+ return { data: user };
1837
+ }
1838
+ }
1839
+ }
1840
+ };
1818
1841
  return (0, import_better_auth.betterAuth)({
1819
1842
  database: databaseOption,
1843
+ databaseHooks: firstUserAdminHook,
1820
1844
  baseURL: baseURL ?? "http://localhost:4000",
1821
1845
  secret: secret ?? process.env["AUTH_SECRET"] ?? "momentum-cms-dev-secret-change-in-production",
1822
1846
  trustedOrigins: trustedOrigins ?? [baseURL ?? "http://localhost:4000"],
package/index.js CHANGED
@@ -1770,8 +1770,32 @@ function createMomentumAuth(config) {
1770
1770
  plugins.push(p);
1771
1771
  }
1772
1772
  }
1773
+ const firstUserAdminHook = {
1774
+ user: {
1775
+ create: {
1776
+ async before(user) {
1777
+ try {
1778
+ let count = 0;
1779
+ if (dbConfig.type === "sqlite") {
1780
+ const row2 = dbConfig.database.prepare('SELECT COUNT(*) as cnt FROM "user"').get();
1781
+ count = row2 && typeof row2 === "object" && "cnt" in row2 ? Number(row2.cnt) : 0;
1782
+ } else {
1783
+ const result = await dbConfig.pool.query('SELECT COUNT(*) as cnt FROM "user"');
1784
+ count = Number(result.rows[0]?.cnt ?? 0);
1785
+ }
1786
+ if (count === 0) {
1787
+ return { data: { ...user, role: "admin" } };
1788
+ }
1789
+ } catch {
1790
+ }
1791
+ return { data: user };
1792
+ }
1793
+ }
1794
+ }
1795
+ };
1773
1796
  return betterAuth({
1774
1797
  database: databaseOption,
1798
+ databaseHooks: firstUserAdminHook,
1775
1799
  baseURL: baseURL ?? "http://localhost:4000",
1776
1800
  secret: secret ?? process.env["AUTH_SECRET"] ?? "momentum-cms-dev-secret-change-in-production",
1777
1801
  trustedOrigins: trustedOrigins ?? [baseURL ?? "http://localhost:4000"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momentumcms/auth",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "description": "Better Auth integration for Momentum CMS",
5
5
  "license": "MIT",
6
6
  "author": "Momentum CMS Contributors",