Rename some auth0 mgmt things
This commit is contained in:
parent
81502395ec
commit
dc1312c970
8 changed files with 84 additions and 14 deletions
63
apps/cf-webapp/package.json
Normal file
63
apps/cf-webapp/package.json
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
{
|
||||
"name": "codeflash-webapp",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "npm install --omit=dev --loglevel verbose && npx prisma generate && next build",
|
||||
"deploy": "az webapp up -n codeflash-webapp-2 --sku P1V2 --runtime NODE:20-lts",
|
||||
"start": "next start",
|
||||
"lint": "next lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@auth0/nextjs-auth0": "^3.3.0",
|
||||
"@hookform/resolvers": "^3.3.2",
|
||||
"@prisma/client": "^5.6.0",
|
||||
"@radix-ui/react-dialog": "^1.0.5",
|
||||
"@radix-ui/react-dropdown-menu": "^2.0.6",
|
||||
"@radix-ui/react-label": "^2.0.2",
|
||||
"@radix-ui/react-navigation-menu": "^1.1.4",
|
||||
"@radix-ui/react-select": "^2.0.0",
|
||||
"@radix-ui/react-separator": "^1.0.3",
|
||||
"@radix-ui/react-slot": "^1.0.2",
|
||||
"@radix-ui/react-toast": "^1.1.5",
|
||||
"@types/node": "^20",
|
||||
"@types/pg": "^8.10.9",
|
||||
"@types/react": "^18",
|
||||
"@types/react-dom": "^18",
|
||||
"@typescript-eslint/eslint-plugin": "^6.13.1",
|
||||
"autoprefixer": "^10.0.1",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"clsx": "^2.0.0",
|
||||
"@codeflash-ai/common": "1.0.0",
|
||||
"eslint": "^8.54.0",
|
||||
"eslint-config-next": "14.0.3",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-config-standard-with-typescript": "^40.0.0",
|
||||
"eslint-plugin-import": "^2.29.0",
|
||||
"eslint-plugin-n": "^16.3.1",
|
||||
"eslint-plugin-promise": "^6.1.1",
|
||||
"eslint-plugin-react": "^7.33.2",
|
||||
"lucide-react": "^0.293.0",
|
||||
"next": "14.0.4",
|
||||
"next-themes": "^0.2.1",
|
||||
"pg": "^8.11.3",
|
||||
"postcss": "^8",
|
||||
"prisma": "^5.6.0",
|
||||
"react": "^18",
|
||||
"react-dom": "^18",
|
||||
"react-hook-form": "^7.48.2",
|
||||
"react-markdown": "^9.0.1",
|
||||
"tailwind-merge": "^2.0.0",
|
||||
"tailwindcss": "^3.3.0",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
"typescript": "^5.3.2",
|
||||
"zod": "^3.22.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "3.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0 < 21.0.0"
|
||||
}
|
||||
}
|
||||
|
|
@ -2,9 +2,9 @@ import { ManagementClient } from "auth0"
|
|||
|
||||
export async function userNickname(userId: string): Promise<string | null> {
|
||||
const m = new ManagementClient({
|
||||
domain: process.env.AUTH0_ISSUER_BASE_URL || "",
|
||||
clientId: process.env.AUTH0_CLIENT_ID_MANAGEMENT || "",
|
||||
clientSecret: process.env.AUTH0_CLIENT_SECRET_MANAGEMENT || "",
|
||||
domain: process.env.AUTH0_ISSUER_BASE_URL ?? "",
|
||||
clientId: process.env.AUTH0_MANAGEMENT_CLIENT_ID ?? "",
|
||||
clientSecret: process.env.AUTH0_MANAGEMENT_CLIENT_SECRET ?? "",
|
||||
})
|
||||
try {
|
||||
const user = await m.users.get({ id: userId, fields: "nickname" })
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import dotenv from "dotenv"
|
||||
import { createNodeMiddleware } from "octokit"
|
||||
import express from "express"
|
||||
import suggester from "code-suggester"
|
||||
|
|
@ -6,18 +7,20 @@ import { type FileDiffContent } from "code-suggester/build/src/types"
|
|||
import { determineValidHunks, objectToMap } from "./utils"
|
||||
import { createPullRequestFromDiffContents } from "./create-pr-from-diffcontents"
|
||||
import { githubApp, webhookApiPath } from "./github-app"
|
||||
import { userNickname } from "./auth0-mgmt"
|
||||
|
||||
import functions from "@codeflash-ai/common/token-functions"
|
||||
import dotenv from "dotenv"
|
||||
import { userNickname } from "./auth0-utils"
|
||||
import * as console from "console"
|
||||
|
||||
const userForAPIKey = functions.userForAPIKey
|
||||
|
||||
const port = process.env.PORT || 3001
|
||||
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
console.log("Using .env.local file to supply config environment variables")
|
||||
dotenv.config({ path: ".env.local" })
|
||||
}
|
||||
|
||||
const port = process.env.PORT || 3001
|
||||
|
||||
const appExpress = express()
|
||||
|
||||
appExpress.use((req, res, next) => {
|
||||
|
|
@ -52,6 +55,7 @@ appExpress.use(async (req, res, next) => {
|
|||
const apiKey = authHeader.replace(/^Bearer\s+/, "")
|
||||
const userId = await userForAPIKey(apiKey)
|
||||
if (userId == null) {
|
||||
console.log(`Userid null for API key ${apiKey}. Returning 403`)
|
||||
return res.status(403).send("Invalid API key")
|
||||
}
|
||||
req.userId = userId
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
"type": "module",
|
||||
"scripts": {
|
||||
"npx": "npx",
|
||||
"build": "npm install --loglevel verbose && npx prisma generate",
|
||||
"deploy": "az webapp up -n codeflash-api --sku P1V2 --runtime NODE:20-lts",
|
||||
"start": "npx tsx index.ts"
|
||||
},
|
||||
|
|
@ -12,7 +13,7 @@
|
|||
"@azure/identity": "^4.0.0",
|
||||
"@azure/keyvault-keys": "^4.7.2",
|
||||
"@azure/keyvault-secrets": "^4.7.0",
|
||||
"@codeflash-ai/common": "1.0.1",
|
||||
"@codeflash-ai/common": "1.0.2",
|
||||
"@prisma/client": "^5.6.0",
|
||||
"auth0": "^4.2.0",
|
||||
"body-parser": "^1.20.2",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@codeflash-ai/common",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
"main": "index.ts",
|
||||
"types": "index.d.ts",
|
||||
"repository": "https://github.com/codeflash-ai/codeflash.git",
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
"use server"
|
||||
import util from "util"
|
||||
import {createHash, type Hash, randomBytes} from "crypto"
|
||||
import {prisma} from "./index"
|
||||
import {cf_api_keys} from "@prisma/client";
|
||||
import { createHash, type Hash, randomBytes } from "crypto"
|
||||
import { prisma } from "./index"
|
||||
import { cf_api_keys } from "@prisma/client"
|
||||
|
||||
// const prisma = new PrismaClient()
|
||||
async function generateRandomAPIToken(): Promise<string> {
|
||||
|
|
@ -55,20 +55,22 @@ export async function userForAPIKey(key: string): Promise<null | string> {
|
|||
},
|
||||
})
|
||||
if (result == null) {
|
||||
console.log(`No user found for API key ${key}`)
|
||||
return null
|
||||
} else {
|
||||
return result.user_id
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(`Error in userForAPIKey: ${e}`)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteAPIKeyById(id: number, userId: string): Promise<cf_api_keys> {
|
||||
export async function deleteAPIKeyById(id: number, userId: string): Promise<cf_api_keys> {
|
||||
return prisma.cf_api_keys.delete({
|
||||
where: {
|
||||
id,
|
||||
user_id: userId,
|
||||
},
|
||||
});
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue