refactor: remove yearly billing interval, keep only one_time and monthly
This commit is contained in:
50
shop/lib/actions/users.ts
Normal file
50
shop/lib/actions/users.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
'use server'
|
||||
|
||||
import { createAdminClient } from '@/lib/supabase/admin'
|
||||
import { revalidatePath } from 'next/cache'
|
||||
|
||||
export async function getUsers() {
|
||||
const admin = createAdminClient()
|
||||
const { data: { users }, error } = await admin.auth.admin.listUsers()
|
||||
if (error) throw error
|
||||
return users
|
||||
}
|
||||
|
||||
export async function createUser(data: { email: string; password?: string; email_confirm?: boolean }) {
|
||||
const admin = createAdminClient()
|
||||
const { data: { user }, error } = await admin.auth.admin.createUser({
|
||||
email: data.email,
|
||||
password: data.password || Math.random().toString(36).slice(-10),
|
||||
email_confirm: data.email_confirm ?? true,
|
||||
})
|
||||
if (error) throw error
|
||||
revalidatePath('/admin/users')
|
||||
return user
|
||||
}
|
||||
|
||||
export async function deleteUser(id: string) {
|
||||
const admin = createAdminClient()
|
||||
const { error } = await admin.auth.admin.deleteUser(id)
|
||||
if (error) throw error
|
||||
revalidatePath('/admin/users')
|
||||
}
|
||||
|
||||
export async function updateUserStatus(id: string, ban: boolean) {
|
||||
const admin = createAdminClient()
|
||||
const { error } = await admin.auth.admin.updateUserById(id, {
|
||||
ban_duration: ban ? '876000h' : '0h', // 100 years or none
|
||||
})
|
||||
if (error) throw error
|
||||
revalidatePath('/admin/users')
|
||||
}
|
||||
|
||||
export async function resetPassword(email: string) {
|
||||
const admin = createAdminClient()
|
||||
// Generate a reset link or send email
|
||||
const { error } = await admin.auth.admin.generateLink({
|
||||
type: 'recovery',
|
||||
email,
|
||||
})
|
||||
if (error) throw error
|
||||
// Usually you'd send this link or let Supabase handle it via regular auth.resetPasswordForEmail
|
||||
}
|
||||
16
shop/lib/supabase/admin.ts
Normal file
16
shop/lib/supabase/admin.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { createClient } from '@supabase/supabase-js'
|
||||
|
||||
export function createAdminClient() {
|
||||
const serviceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU'
|
||||
|
||||
return createClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
serviceRoleKey,
|
||||
{
|
||||
auth: {
|
||||
autoRefreshToken: false,
|
||||
persistSession: false
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -4,7 +4,7 @@ export type Product = {
|
||||
description?: string | null | undefined;
|
||||
base_price: number;
|
||||
is_active: boolean;
|
||||
billing_interval: 'one_time' | 'monthly' | 'yearly';
|
||||
billing_interval: 'one_time' | 'monthly';
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
category_id?: string | null;
|
||||
|
||||
Reference in New Issue
Block a user