mirror of
https://github.com/documenso/documenso.git
synced 2025-11-22 20:51:33 +10:00
feat: update signin signup ui
Signed-off-by: Adithya Krishna <adithya@documenso.com>
This commit is contained in:
14
packages/lib/server-only/user/get-public-profile.ts
Normal file
14
packages/lib/server-only/user/get-public-profile.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import type { UserProfile } from '@documenso/prisma/client';
|
||||
|
||||
export interface GetPublicProfileByURLOptions {
|
||||
profileURL: UserProfile['profileURL'];
|
||||
}
|
||||
|
||||
export const getPublicProfileByURL = async ({ profileURL }: GetPublicProfileByURLOptions) => {
|
||||
return await prisma.userProfile.findFirstOrThrow({
|
||||
where: {
|
||||
profileURL: profileURL,
|
||||
},
|
||||
});
|
||||
};
|
||||
32
packages/lib/server-only/user/update-public-profile.ts
Normal file
32
packages/lib/server-only/user/update-public-profile.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import type { User, UserProfile } from '@documenso/prisma/client';
|
||||
|
||||
import { getUserById } from './get-user-by-id';
|
||||
|
||||
export type UpdatePublicProfileOptions = {
|
||||
id: User['id'];
|
||||
userProfile: UserProfile;
|
||||
};
|
||||
|
||||
export const updatePublicProfile = async ({ id, userProfile }: UpdatePublicProfileOptions) => {
|
||||
const user = await getUserById({ id });
|
||||
console.log('Adi', user);
|
||||
// Existence check
|
||||
await prisma.userProfile.findFirstOrThrow({
|
||||
where: {
|
||||
profileURL: user.profileURL ?? '',
|
||||
},
|
||||
});
|
||||
|
||||
return await prisma.$transaction(async (tx) => {
|
||||
await tx.userProfile.update({
|
||||
where: {
|
||||
profileURL: user.profileURL!,
|
||||
},
|
||||
data: {
|
||||
profileURL: userProfile.profileURL,
|
||||
profileBio: userProfile.profileBio,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
@ -0,0 +1,25 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[profileURL]` on the table `User` will be added. If there are existing duplicate values, this will fail.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "User" ADD COLUMN "profileURL" TEXT;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "UserProfile" (
|
||||
"profileURL" TEXT NOT NULL,
|
||||
"profileBio" TEXT,
|
||||
|
||||
CONSTRAINT "UserProfile_pkey" PRIMARY KEY ("profileURL")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "UserProfile_profileURL_key" ON "UserProfile"("profileURL");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "User_profileURL_key" ON "User"("profileURL");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "User" ADD CONSTRAINT "User_profileURL_fkey" FOREIGN KEY ("profileURL") REFERENCES "UserProfile"("profileURL") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@ -43,6 +43,9 @@ model User {
|
||||
twoFactorSecret String?
|
||||
twoFactorEnabled Boolean @default(false)
|
||||
twoFactorBackupCodes String?
|
||||
profileURL String? @unique
|
||||
|
||||
UserProfile UserProfile? @relation(fields: [profileURL], references: [profileURL], onDelete: Cascade)
|
||||
|
||||
VerificationToken VerificationToken[]
|
||||
Template Template[]
|
||||
@ -51,6 +54,13 @@ model User {
|
||||
@@index([email])
|
||||
}
|
||||
|
||||
model UserProfile {
|
||||
profileURL String @id @unique
|
||||
profileBio String?
|
||||
|
||||
User User?
|
||||
}
|
||||
|
||||
enum UserSecurityAuditLogType {
|
||||
ACCOUNT_PROFILE_UPDATE
|
||||
ACCOUNT_SSO_LINK
|
||||
|
||||
@ -7,6 +7,7 @@ import { resetPassword } from '@documenso/lib/server-only/user/reset-password';
|
||||
import { sendConfirmationToken } from '@documenso/lib/server-only/user/send-confirmation-token';
|
||||
import { updatePassword } from '@documenso/lib/server-only/user/update-password';
|
||||
import { updateProfile } from '@documenso/lib/server-only/user/update-profile';
|
||||
import { updatePublicProfile } from '@documenso/lib/server-only/user/update-public-profile';
|
||||
import { extractNextApiRequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
||||
|
||||
import { adminProcedure, authenticatedProcedure, procedure, router } from '../trpc';
|
||||
@ -18,6 +19,7 @@ import {
|
||||
ZRetrieveUserByIdQuerySchema,
|
||||
ZUpdatePasswordMutationSchema,
|
||||
ZUpdateProfileMutationSchema,
|
||||
ZUpdatePublicProfileMutationSchema,
|
||||
} from './schema';
|
||||
|
||||
export const profileRouter = router({
|
||||
@ -73,6 +75,27 @@ export const profileRouter = router({
|
||||
}
|
||||
}),
|
||||
|
||||
updatePublicProfile: authenticatedProcedure
|
||||
.input(ZUpdatePublicProfileMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
try {
|
||||
const { profileURL, profileBio } = input;
|
||||
|
||||
return await updatePublicProfile({
|
||||
id: ctx.user.id,
|
||||
userProfile: { profileURL, profileBio },
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
message:
|
||||
'We were unable to update your public profile. Please review the information you provided and try again.',
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
||||
updatePassword: authenticatedProcedure
|
||||
.input(ZUpdatePasswordMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
|
||||
@ -16,6 +16,11 @@ export const ZUpdateProfileMutationSchema = z.object({
|
||||
signature: z.string(),
|
||||
});
|
||||
|
||||
export const ZUpdatePublicProfileMutationSchema = z.object({
|
||||
profileURL: z.string().min(1),
|
||||
profileBio: z.string().max(256, { message: 'Profile bio must not exceed 256 characters' }),
|
||||
});
|
||||
|
||||
export const ZUpdatePasswordMutationSchema = z.object({
|
||||
currentPassword: ZCurrentPasswordSchema,
|
||||
password: ZPasswordSchema,
|
||||
|
||||
@ -17,11 +17,7 @@ export const AnnouncementBar: React.FC<AnnouncementBarProps> = ({ isShown }) =>
|
||||
|
||||
<div className="flex items-center justify-center gap-4 rounded-lg bg-white px-3 py-1">
|
||||
<div className="text-xs text-gray-900">
|
||||
<Link
|
||||
href="https://app.documenso.com"
|
||||
>
|
||||
Claim now
|
||||
</Link>
|
||||
<Link href="https://app.documenso.com">Claim now</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user