mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 06:54:28 +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 () => {
|
it('GET /signup-info', async () => {
|
||||||
mockGetSignupInfo.mockResolvedValue({
|
mockGetSignupInfo.mockResolvedValue({
|
||||||
userCount: 5,
|
userCount: 5,
|
||||||
enablePublicSignup: true,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const app = new Hono().route('/', authnRoute)
|
const app = new Hono().route('/', authnRoute)
|
||||||
@@ -27,7 +26,6 @@ describe('authn api', () => {
|
|||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
expect(await res.json()).toEqual({
|
expect(await res.json()).toEqual({
|
||||||
userCount: 5,
|
userCount: 5,
|
||||||
enablePublicSignup: true,
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ const route = app
|
|||||||
const info = await teamService.getSignupInfo()
|
const info = await teamService.getSignupInfo()
|
||||||
return c.json({
|
return c.json({
|
||||||
userCount: info.userCount,
|
userCount: info.userCount,
|
||||||
enablePublicSignup: info.enablePublicSignup,
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.get('/me', async (c) => {
|
.get('/me', async (c) => {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export const auth = betterAuth({
|
|||||||
const info = await teamService.getSignupInfo()
|
const info = await teamService.getSignupInfo()
|
||||||
|
|
||||||
if (info.userCount > 0) {
|
if (info.userCount > 0) {
|
||||||
if (!inviteCode && !info.enablePublicSignup) {
|
if (!inviteCode) {
|
||||||
console.log('[Better Auth Hook] Public signup is disabled')
|
console.log('[Better Auth Hook] Public signup is disabled')
|
||||||
return ctx.json(
|
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: {
|
data: {
|
||||||
name: 'Test Team',
|
name: 'Test Team',
|
||||||
settings: {
|
settings: {
|
||||||
enablePublicSignup: true,
|
|
||||||
transcode: { videoStrategy: 'best_match' },
|
transcode: { videoStrategy: 'best_match' },
|
||||||
},
|
},
|
||||||
sandbox: { create: {} },
|
sandbox: { create: {} },
|
||||||
|
|||||||
@@ -61,6 +61,22 @@ export class InviteService {
|
|||||||
return inv
|
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> {
|
async consumeInvite(code: string, userId: string): Promise<void> {
|
||||||
await prisma.$transaction(async (tx) => {
|
await prisma.$transaction(async (tx) => {
|
||||||
const inv = await tx.invite.findUniqueOrThrow({
|
const inv = await tx.invite.findUniqueOrThrow({
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ export class TeamService {
|
|||||||
data: {
|
data: {
|
||||||
name: 'Default Team',
|
name: 'Default Team',
|
||||||
settings: {
|
settings: {
|
||||||
enablePublicSignup: true,
|
|
||||||
transcode: { videoStrategy: 'best_match' },
|
transcode: { videoStrategy: 'best_match' },
|
||||||
},
|
},
|
||||||
sandbox: { create: {} },
|
sandbox: { create: {} },
|
||||||
@@ -249,14 +248,9 @@ export class TeamService {
|
|||||||
|
|
||||||
async getSignupInfo() {
|
async getSignupInfo() {
|
||||||
const count = await prisma.user.count()
|
const count = await prisma.user.count()
|
||||||
const defaultTeam = await this.ensureDefaultTeam()
|
|
||||||
const settings = defaultTeam.settings as {
|
|
||||||
enablePublicSignup?: boolean
|
|
||||||
} | null
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
userCount: count,
|
userCount: count,
|
||||||
enablePublicSignup: settings?.enablePublicSignup ?? false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ declare global {
|
|||||||
|
|
||||||
export interface Settings {
|
export interface Settings {
|
||||||
transcode: TranscodeSettings
|
transcode: TranscodeSettings
|
||||||
enablePublicSignup: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { z } from 'zod'
|
|||||||
|
|
||||||
export const signupInfoResponseSchema = z.object({
|
export const signupInfoResponseSchema = z.object({
|
||||||
userCount: z.number(),
|
userCount: z.number(),
|
||||||
enablePublicSignup: z.boolean(),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export type SignupInfoResponse = z.infer<typeof signupInfoResponseSchema>
|
export type SignupInfoResponse = z.infer<typeof signupInfoResponseSchema>
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ function SignupPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isFirstUser = signupInfo?.userCount === 0
|
const isFirstUser = signupInfo?.userCount === 0
|
||||||
const isPublicSignupDisabled = !isFirstUser && !signupInfo?.enablePublicSignup && !inviteCode
|
const isPublicSignupDisabled = !isFirstUser && !inviteCode
|
||||||
|
|
||||||
if (isPublicSignupDisabled) {
|
if (isPublicSignupDisabled) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import { SandboxSettings } from '@/ui/components/settings/SandboxSettings'
|
|||||||
import { SkillsConfigCard } from '@/ui/components/settings/SkillsConfigCard'
|
import { SkillsConfigCard } from '@/ui/components/settings/SkillsConfigCard'
|
||||||
import { NotificationSettings } from '@/ui/components/settings/NotificationSettings'
|
import { NotificationSettings } from '@/ui/components/settings/NotificationSettings'
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/ui/components/ui/card'
|
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 { cn } from '@/ui/lib/utils'
|
||||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
import { createFileRoute } from '@tanstack/react-router'
|
import { createFileRoute } from '@tanstack/react-router'
|
||||||
@@ -275,38 +274,6 @@ function TeamSettingsPage() {
|
|||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</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>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user