mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-22 22:49:03 +00:00
Merge pull request #56 from shumaiOne/feat/remove-public-signup
feat(auth): remove public signup
This commit is contained in:
@@ -18,7 +18,6 @@ describe('authn api', () => {
|
||||
it('GET /signup-info', async () => {
|
||||
mockGetSignupInfo.mockResolvedValue({
|
||||
userCount: 5,
|
||||
enablePublicSignup: true,
|
||||
})
|
||||
|
||||
const app = new Hono().route('/', authnRoute)
|
||||
@@ -27,7 +26,6 @@ describe('authn api', () => {
|
||||
expect(res.status).toBe(200)
|
||||
expect(await res.json()).toEqual({
|
||||
userCount: 5,
|
||||
enablePublicSignup: true,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -18,7 +18,6 @@ const route = app
|
||||
const info = await teamService.getSignupInfo()
|
||||
return c.json({
|
||||
userCount: info.userCount,
|
||||
enablePublicSignup: info.enablePublicSignup,
|
||||
})
|
||||
})
|
||||
.get('/me', async (c) => {
|
||||
|
||||
@@ -31,7 +31,7 @@ export const auth = betterAuth({
|
||||
const info = await teamService.getSignupInfo()
|
||||
|
||||
if (info.userCount > 0) {
|
||||
if (!inviteCode && !info.enablePublicSignup) {
|
||||
if (!inviteCode) {
|
||||
console.log('[Better Auth Hook] Public signup is disabled')
|
||||
return ctx.json(
|
||||
{
|
||||
@@ -42,6 +42,18 @@ export const auth = betterAuth({
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
const isValid = await inviteService.validateInvite(inviteCode)
|
||||
if (!isValid) {
|
||||
return ctx.json(
|
||||
{
|
||||
error: 'Invalid or expired invite code',
|
||||
},
|
||||
{
|
||||
status: 400,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
@@ -15,7 +15,6 @@ describe('CollectionService', () => {
|
||||
data: {
|
||||
name: 'Test Team',
|
||||
settings: {
|
||||
enablePublicSignup: true,
|
||||
transcode: { videoStrategy: 'best_match' },
|
||||
},
|
||||
sandbox: { create: {} },
|
||||
|
||||
@@ -61,6 +61,22 @@ export class InviteService {
|
||||
return inv
|
||||
}
|
||||
|
||||
async validateInvite(code: string): Promise<boolean> {
|
||||
const inv = await prisma.invite.findUnique({
|
||||
where: { code },
|
||||
})
|
||||
|
||||
if (!inv) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (inv.used) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
async consumeInvite(code: string, userId: string): Promise<void> {
|
||||
await prisma.$transaction(async (tx) => {
|
||||
const inv = await tx.invite.findUniqueOrThrow({
|
||||
|
||||
@@ -26,7 +26,6 @@ export class TeamService {
|
||||
data: {
|
||||
name: 'Default Team',
|
||||
settings: {
|
||||
enablePublicSignup: true,
|
||||
transcode: { videoStrategy: 'best_match' },
|
||||
},
|
||||
sandbox: { create: {} },
|
||||
@@ -249,14 +248,9 @@ export class TeamService {
|
||||
|
||||
async getSignupInfo() {
|
||||
const count = await prisma.user.count()
|
||||
const defaultTeam = await this.ensureDefaultTeam()
|
||||
const settings = defaultTeam.settings as {
|
||||
enablePublicSignup?: boolean
|
||||
} | null
|
||||
|
||||
return {
|
||||
userCount: count,
|
||||
enablePublicSignup: settings?.enablePublicSignup ?? false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,6 @@ declare global {
|
||||
|
||||
export interface Settings {
|
||||
transcode: TranscodeSettings
|
||||
enablePublicSignup: boolean
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@@ -2,7 +2,6 @@ import { z } from 'zod'
|
||||
|
||||
export const signupInfoResponseSchema = z.object({
|
||||
userCount: z.number(),
|
||||
enablePublicSignup: z.boolean(),
|
||||
})
|
||||
|
||||
export type SignupInfoResponse = z.infer<typeof signupInfoResponseSchema>
|
||||
|
||||
@@ -96,7 +96,7 @@ function SignupPage() {
|
||||
}
|
||||
|
||||
const isFirstUser = signupInfo?.userCount === 0
|
||||
const isPublicSignupDisabled = !isFirstUser && !signupInfo?.enablePublicSignup && !inviteCode
|
||||
const isPublicSignupDisabled = !isFirstUser && !inviteCode
|
||||
|
||||
if (isPublicSignupDisabled) {
|
||||
return (
|
||||
|
||||
@@ -6,7 +6,6 @@ import { SandboxSettings } from '@/ui/components/settings/SandboxSettings'
|
||||
import { SkillsConfigCard } from '@/ui/components/settings/SkillsConfigCard'
|
||||
import { NotificationSettings } from '@/ui/components/settings/NotificationSettings'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/ui/components/ui/card'
|
||||
import { Switch } from '@/ui/components/ui/switch'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { createFileRoute } from '@tanstack/react-router'
|
||||
@@ -275,38 +274,6 @@ function TeamSettingsPage() {
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{me?.role === 'owner' && (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Team Settings</CardTitle>
|
||||
<CardDescription>Manage your team's general settings.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="space-y-0.5">
|
||||
<h3 className="text-base font-medium">Enable Public Signup</h3>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Allow users to sign up without an invite code.
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
checked={(settings as any)?.enablePublicSignup || false}
|
||||
onCheckedChange={(checked) =>
|
||||
updateSettings({
|
||||
teamId,
|
||||
data: {
|
||||
key: 'enablePublicSignup',
|
||||
value: checked,
|
||||
},
|
||||
})
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user