create-kofi-stack 1.2.12 → 1.2.13

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 (2) hide show
  1. package/dist/index.js +49 -21
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1877,47 +1877,74 @@ export default defineSchema({
1877
1877
  await writeFile(path6.join(convexDir, "schema.ts"), content);
1878
1878
  }
1879
1879
  async function generateAuthTs(config, convexDir) {
1880
- let content = `import { BetterAuth } from '@convex-dev/better-auth'
1880
+ let content = `import { createClient, type GenericCtx } from '@convex-dev/better-auth'
1881
+ import { convex } from '@convex-dev/better-auth/plugins'
1882
+ import { betterAuth } from 'better-auth'
1881
1883
  import { components } from './_generated/api'
1882
1884
  import type { DataModel } from './_generated/dataModel'
1885
+ import { query } from './_generated/server'
1886
+ import authConfig from './auth.config'
1883
1887
 
1884
- export const { auth, createAuth } = new BetterAuth<DataModel>(components.betterAuth, {
1885
- emailAndPassword: {
1886
- enabled: true,
1887
- },
1888
- socialProviders: {
1889
- google: {
1890
- clientId: process.env.GOOGLE_CLIENT_ID!,
1891
- clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
1892
- },`;
1888
+ const siteUrl = process.env.SITE_URL || process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000'
1889
+
1890
+ // The component client has methods for integrating Convex with Better Auth
1891
+ export const authComponent = createClient<DataModel>(components.betterAuth)
1892
+
1893
+ // Create the Better Auth instance with Convex adapter
1894
+ export const createAuth = (ctx: GenericCtx<DataModel>) => {
1895
+ return betterAuth({
1896
+ baseURL: siteUrl,
1897
+ database: authComponent.adapter(ctx),
1898
+ emailAndPassword: {
1899
+ enabled: true,
1900
+ requireEmailVerification: false,
1901
+ },
1902
+ socialProviders: {
1903
+ google: {
1904
+ clientId: process.env.GOOGLE_CLIENT_ID!,
1905
+ clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
1906
+ },`;
1893
1907
  for (const provider of config.auth.providers) {
1894
1908
  const envPrefix = provider.toUpperCase();
1895
1909
  content += `
1896
- ${provider}: {
1897
- clientId: process.env.${envPrefix}_CLIENT_ID!,
1898
- clientSecret: process.env.${envPrefix}_CLIENT_SECRET!,
1899
- },`;
1910
+ ${provider}: {
1911
+ clientId: process.env.${envPrefix}_CLIENT_ID!,
1912
+ clientSecret: process.env.${envPrefix}_CLIENT_SECRET!,
1913
+ },`;
1900
1914
  }
1901
1915
  content += `
1902
- },`;
1916
+ },`;
1903
1917
  if (config.auth.organizations) {
1904
1918
  content += `
1905
- organization: {
1906
- enabled: true,
1907
- },`;
1919
+ organization: {
1920
+ enabled: true,
1921
+ },`;
1908
1922
  }
1909
1923
  content += `
1924
+ plugins: [
1925
+ convex({ authConfig }),
1926
+ ],
1927
+ })
1928
+ }
1929
+
1930
+ // Get the current authenticated user
1931
+ export const getCurrentUser = query({
1932
+ args: {},
1933
+ handler: async (ctx) => {
1934
+ return authComponent.getAuthUser(ctx)
1935
+ },
1910
1936
  })
1911
1937
  `;
1912
1938
  await writeFile(path6.join(convexDir, "auth.ts"), content);
1913
1939
  }
1914
1940
  async function generateHttp(convexDir) {
1915
1941
  const content = `import { httpRouter } from 'convex/server'
1916
- import { auth } from './auth'
1942
+ import { authComponent } from './auth'
1917
1943
 
1918
1944
  const http = httpRouter()
1919
1945
 
1920
- auth.addHttpRoutes(http)
1946
+ // Add Better Auth HTTP routes
1947
+ authComponent.addHttpRoutes(http)
1921
1948
 
1922
1949
  export default http
1923
1950
  `;
@@ -1990,7 +2017,8 @@ async function generateConvexPackageJson(convexDir) {
1990
2017
  types: "./convex/index.ts",
1991
2018
  dependencies: {
1992
2019
  convex: "^1.25.0",
1993
- "@convex-dev/better-auth": "^0.10.10"
2020
+ "@convex-dev/better-auth": "^0.10.10",
2021
+ "better-auth": "^1.4.9"
1994
2022
  },
1995
2023
  devDependencies: {
1996
2024
  typescript: "^5.0.0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-kofi-stack",
3
- "version": "1.2.12",
3
+ "version": "1.2.13",
4
4
  "description": "Scaffold opinionated full-stack projects with Next.js, Convex, Better-Auth, and more",
5
5
  "type": "module",
6
6
  "bin": {