mirror of
https://github.com/jorgev259/soc_site-astro.git
synced 2025-06-29 07:57:41 +00:00
WIP
This commit is contained in:
parent
c3fca425cb
commit
392d6b6e51
5 changed files with 62 additions and 5 deletions
|
|
@ -20,7 +20,7 @@
|
||||||
"@types/react-dom": "^18.3.1",
|
"@types/react-dom": "^18.3.1",
|
||||||
"astro": "^5.3.0",
|
"astro": "^5.3.0",
|
||||||
"astro-icon": "^1.1.1",
|
"astro-icon": "^1.1.1",
|
||||||
"better-auth": "^1.1.11",
|
"better-auth": "^1.2.3",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"nodemailer": "^6.10.0",
|
"nodemailer": "^6.10.0",
|
||||||
"prisma": "^6.4.1",
|
"prisma": "^6.4.1",
|
||||||
|
|
|
||||||
29
prisma/migrations/20250308034728_api_support/migration.sql
Normal file
29
prisma/migrations/20250308034728_api_support/migration.sql
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `apiKey` (
|
||||||
|
`id` VARCHAR(191) NOT NULL,
|
||||||
|
`name` VARCHAR(191) NULL,
|
||||||
|
`start` VARCHAR(191) NULL,
|
||||||
|
`prefix` VARCHAR(191) NULL,
|
||||||
|
`key` VARCHAR(191) NOT NULL,
|
||||||
|
`userId` VARCHAR(255) NOT NULL,
|
||||||
|
`refillInterval` INTEGER NULL,
|
||||||
|
`refillAmmount` INTEGER NULL,
|
||||||
|
`lastRefillAt` DATETIME(3) NULL,
|
||||||
|
`enabled` BOOLEAN NOT NULL,
|
||||||
|
`rateLimitEnabled` BOOLEAN NOT NULL,
|
||||||
|
`rateLimitTimeWindow` INTEGER NULL,
|
||||||
|
`rateLimitMax` INTEGER NULL,
|
||||||
|
`requestCount` INTEGER NOT NULL,
|
||||||
|
`remaining` INTEGER NULL,
|
||||||
|
`lastRequest` DATETIME(3) NULL,
|
||||||
|
`expiresAt` DATETIME(3) NULL,
|
||||||
|
`createdAt` DATETIME(3) NOT NULL,
|
||||||
|
`updatedAt` DATETIME(3) NOT NULL,
|
||||||
|
`permissions` VARCHAR(191) NULL,
|
||||||
|
`metadata` JSON NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE `apiKey` ADD CONSTRAINT `apiKey_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
@ -451,6 +451,7 @@ model users {
|
||||||
submissions submissions[]
|
submissions submissions[]
|
||||||
sessions session[]
|
sessions session[]
|
||||||
accounts account[]
|
accounts account[]
|
||||||
|
ApiKey ApiKey[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model session {
|
model session {
|
||||||
|
|
@ -492,3 +493,30 @@ model account {
|
||||||
|
|
||||||
user users @relation(fields: [userId], references: [id])
|
user users @relation(fields: [userId], references: [id])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model ApiKey {
|
||||||
|
id String @id
|
||||||
|
name String?
|
||||||
|
start String?
|
||||||
|
prefix String?
|
||||||
|
key String
|
||||||
|
userId String @db.VarChar(255)
|
||||||
|
user users @relation(fields: [userId], references: [id])
|
||||||
|
refillInterval Int?
|
||||||
|
refillAmmount Int?
|
||||||
|
lastRefillAt DateTime?
|
||||||
|
enabled Boolean
|
||||||
|
rateLimitEnabled Boolean
|
||||||
|
rateLimitTimeWindow Int?
|
||||||
|
rateLimitMax Int?
|
||||||
|
requestCount Int
|
||||||
|
remaining Int?
|
||||||
|
lastRequest DateTime?
|
||||||
|
expiresAt DateTime?
|
||||||
|
createdAt DateTime
|
||||||
|
updatedAt DateTime
|
||||||
|
permissions String?
|
||||||
|
metadata Json?
|
||||||
|
|
||||||
|
@@map("apiKey")
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { betterAuth } from 'better-auth'
|
import { betterAuth } from 'better-auth'
|
||||||
import { prismaAdapter } from 'better-auth/adapters/prisma'
|
import { prismaAdapter } from 'better-auth/adapters/prisma'
|
||||||
import { username } from 'better-auth/plugins'
|
import { username, apiKey } from 'better-auth/plugins'
|
||||||
|
|
||||||
import prismaClient from './utils/prisma-client'
|
import prismaClient from './utils/prisma-client'
|
||||||
import { sendEmail } from 'utils/email'
|
import { sendEmail } from 'utils/email'
|
||||||
|
|
@ -10,7 +10,7 @@ import verifyTemplate from 'utils/verifyTemplate'
|
||||||
export const auth = betterAuth({
|
export const auth = betterAuth({
|
||||||
database: prismaAdapter(prismaClient, { provider: 'mysql' }),
|
database: prismaAdapter(prismaClient, { provider: 'mysql' }),
|
||||||
user: { modelName: 'users' },
|
user: { modelName: 'users' },
|
||||||
plugins: [username()],
|
plugins: [username(), apiKey()],
|
||||||
emailVerification: {
|
emailVerification: {
|
||||||
sendOnSignUp: true,
|
sendOnSignUp: true,
|
||||||
autoSignInAfterVerification: true,
|
autoSignInAfterVerification: true,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { createAuthClient } from 'better-auth/client'
|
import { createAuthClient } from 'better-auth/client'
|
||||||
import { usernameClient } from 'better-auth/client/plugins'
|
import { apiKeyClient, usernameClient } from 'better-auth/client/plugins'
|
||||||
|
|
||||||
export const authClient = createAuthClient({
|
export const authClient = createAuthClient({
|
||||||
plugins: [usernameClient()]
|
plugins: [usernameClient(), apiKeyClient()]
|
||||||
})
|
})
|
||||||
export const { useSession, signIn, signUp, signOut, forgetPassword, resetPassword } = authClient
|
export const { useSession, signIn, signUp, signOut, forgetPassword, resetPassword } = authClient
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue