mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Ready for 1.1.2-rc.1
This commit is contained in:
@@ -8,7 +8,7 @@ import {admin as adminPlugin, openAPI, Organization, organization} from "better-
|
||||
import {ac, admin, orgAdmin, orgMember, orgOwner, pending, superadmin, user} from "@/lib/auth/permissions";
|
||||
import {headers} from "next/headers";
|
||||
import {count, eq} from "drizzle-orm";
|
||||
import {OrganizationWithMembers, OrganizationWithMembersAndUsers} from "@/db/schema/03_organization";
|
||||
import {OrganizationWithMembersAndUsers} from "@/db/schema/03_organization";
|
||||
|
||||
export const auth = betterAuth({
|
||||
database: drizzleAdapter(db, {
|
||||
@@ -81,8 +81,6 @@ export const auth = betterAuth({
|
||||
async before(user, context) {
|
||||
const userCount = (await db.select({count: count()}).from(drizzleDb.schemas.user))[0].count;
|
||||
const role = userCount === 0 ? "superadmin" : "pending";
|
||||
|
||||
|
||||
return {
|
||||
data: {
|
||||
...user,
|
||||
@@ -335,15 +333,15 @@ export const getOrganization = async ({
|
||||
} = {}): Promise<OrganizationWithMembersAndUsers | null> => {
|
||||
const query =
|
||||
organizationId != null
|
||||
? { organizationId }
|
||||
? {organizationId}
|
||||
: organizationSlug != null
|
||||
? { organizationSlug }
|
||||
? {organizationSlug}
|
||||
: undefined;
|
||||
|
||||
try {
|
||||
const response = await auth.api.getFullOrganization({
|
||||
headers: await headers(),
|
||||
...(query ? { query } : {}),
|
||||
...(query ? {query} : {}),
|
||||
});
|
||||
|
||||
return response as OrganizationWithMembersAndUsers;
|
||||
@@ -382,7 +380,7 @@ export const getLastOrganizationOrFirst = async (userId: string) => {
|
||||
export const createOrganization = async (name: string, slug: string) => {
|
||||
try {
|
||||
return await auth.api.createOrganization({
|
||||
headers: await headers(),
|
||||
headers: await headers(),
|
||||
body: {
|
||||
name,
|
||||
slug,
|
||||
@@ -465,13 +463,12 @@ export const getActiveMember = async () => {
|
||||
|
||||
export const setActiveOrganization = async (slug: string) => {
|
||||
try {
|
||||
const organization = await auth.api.setActiveOrganization({
|
||||
return await auth.api.setActiveOrganization({
|
||||
headers: await headers(),
|
||||
body: {
|
||||
organizationSlug: slug,
|
||||
},
|
||||
});
|
||||
return organization;
|
||||
} catch (e) {
|
||||
console.log("error", e);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import {createSafeActionClient} from "next-safe-action";
|
||||
import {currentUser} from "@/lib/auth/current-user";
|
||||
|
||||
export class ActionError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = "ActionError";
|
||||
}
|
||||
}
|
||||
|
||||
const handleReturnedServerError = (error: Error) => {
|
||||
if (error instanceof ActionError) {
|
||||
return error.message;
|
||||
} else {
|
||||
return "An unexpected error occurred.";
|
||||
}
|
||||
};
|
||||
|
||||
export const action = createSafeActionClient({
|
||||
handleServerError: handleReturnedServerError,
|
||||
});
|
||||
|
||||
export const userAction = action.use(async ({next, ctx}) => {
|
||||
const user = await currentUser();
|
||||
if (!user) {
|
||||
throw new ActionError("You must be logged in");
|
||||
}
|
||||
return next({ctx: {user}});
|
||||
});
|
||||
@@ -3,7 +3,7 @@ import {enforceRetentionCount} from "@/lib/tasks/database/retention-count";
|
||||
import {enforceRetentionDays} from "@/lib/tasks/database/retention-days";
|
||||
import {enforceRetentionGFS} from "@/lib/tasks/database/retention-gsf";
|
||||
import {retentionPolicy} from "@/db/schema/07_database";
|
||||
import {eq, isNull} from "drizzle-orm";
|
||||
import {isNull} from "drizzle-orm";
|
||||
import * as drizzleDb from "@/db";
|
||||
import {eventEmitter} from "../../../../app/api/events/route";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"use server"
|
||||
import {action, userAction} from "@/safe-actions";
|
||||
import {action} from "@/lib/safe-actions/actions";
|
||||
import {z} from "zod";
|
||||
import {ServerActionResult} from "@/types/action-type";
|
||||
import {Backup} from "@/db/schema/07_database";
|
||||
|
||||
Reference in New Issue
Block a user