create-kofi-stack 1.2.11 → 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.
- package/dist/index.js +52 -24
- 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 {
|
|
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
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
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
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
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
|
-
|
|
1906
|
-
|
|
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 {
|
|
1942
|
+
import { authComponent } from './auth'
|
|
1917
1943
|
|
|
1918
1944
|
const http = httpRouter()
|
|
1919
1945
|
|
|
1920
|
-
|
|
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"
|
|
@@ -2768,11 +2796,11 @@ export async function protectRoute(request: Request) {
|
|
|
2768
2796
|
}
|
|
2769
2797
|
`;
|
|
2770
2798
|
await writeFile(path12.join(appDir, "src/lib/arcjet.ts"), content);
|
|
2771
|
-
const
|
|
2799
|
+
const proxyContent = `import { NextResponse } from 'next/server'
|
|
2772
2800
|
import type { NextRequest } from 'next/server'
|
|
2773
2801
|
import { aj } from '@/lib/arcjet'
|
|
2774
2802
|
|
|
2775
|
-
export async function
|
|
2803
|
+
export async function proxy(request: NextRequest) {
|
|
2776
2804
|
// Only protect API routes
|
|
2777
2805
|
if (request.nextUrl.pathname.startsWith('/api')) {
|
|
2778
2806
|
const decision = await aj.protect(request)
|
|
@@ -2792,7 +2820,7 @@ export const config = {
|
|
|
2792
2820
|
matcher: '/api/:path*',
|
|
2793
2821
|
}
|
|
2794
2822
|
`;
|
|
2795
|
-
await writeFile(path12.join(appDir, "src/
|
|
2823
|
+
await writeFile(path12.join(appDir, "src/proxy.ts"), proxyContent);
|
|
2796
2824
|
}
|
|
2797
2825
|
async function generateUpstash(appDir) {
|
|
2798
2826
|
const content = `import { Ratelimit } from '@upstash/ratelimit'
|