@@ -22,6 +22,7 @@ import {
2222 type User ,
2323 users ,
2424} from "@/lib/db/schema" ;
25+ import { isFaultActive } from "@/lib/faults" ;
2526
2627const signInSchema = z . object ( {
2728 email : z . string ( ) . email ( ) . min ( 3 ) . max ( 255 ) ,
@@ -110,8 +111,12 @@ export const signUp = validatedAction(signUpSchema, async (data, formData) => {
110111export async function signOut ( ) {
111112 const user = ( await getUser ( ) ) as User ;
112113 const userWithTeam = await getUserWithTeam ( user . id ) ;
113- await logActivity ( userWithTeam ?. teamId , user . id , ActivityType . SIGN_OUT ) ;
114- ( await cookies ( ) ) . delete ( "session" ) ;
114+ if ( ! ( await isFaultActive ( "signout-activity-log-missing" ) ) ) {
115+ await logActivity ( userWithTeam ?. teamId , user . id , ActivityType . SIGN_OUT ) ;
116+ }
117+ if ( ! ( await isFaultActive ( "signout-cookie-not-cleared" ) ) ) {
118+ ( await cookies ( ) ) . delete ( "session" ) ;
119+ }
115120}
116121
117122const updatePasswordSchema = z . object ( {
@@ -159,12 +164,19 @@ export const updatePassword = validatedActionWithUser(
159164
160165 const newPasswordHash = await hashPassword ( newPassword ) ;
161166 const userWithTeam = await getUserWithTeam ( user . id ) ;
167+ const skipPasswordUpdate = await isFaultActive (
168+ "password-hash-update-skipped" ,
169+ ) ;
162170
163171 await Promise . all ( [
164- db
165- . update ( users )
166- . set ( { passwordHash : newPasswordHash } )
167- . where ( eq ( users . id , user . id ) ) ,
172+ ...( skipPasswordUpdate
173+ ? [ ]
174+ : [
175+ db
176+ . update ( users )
177+ . set ( { passwordHash : newPasswordHash } )
178+ . where ( eq ( users . id , user . id ) ) ,
179+ ] ) ,
168180 logActivity ( userWithTeam ?. teamId , user . id , ActivityType . UPDATE_PASSWORD ) ,
169181 ] ) ;
170182
@@ -234,10 +246,23 @@ export const updateAccount = validatedActionWithUser(
234246 async ( data , _ , user ) => {
235247 const { name, email } = data ;
236248 const userWithTeam = await getUserWithTeam ( user . id ) ;
249+ const skipAccountUpdate = await isFaultActive (
250+ "account-update-db-write-skipped" ,
251+ ) ;
252+ const skipActivityLog = await isFaultActive ( "activity-update-log-missing" ) ;
253+ const activityType = ( await isFaultActive (
254+ "activity-update-log-mislabelled" ,
255+ ) )
256+ ? ActivityType . UPDATE_PASSWORD
257+ : ActivityType . UPDATE_ACCOUNT ;
237258
238259 await Promise . all ( [
239- db . update ( users ) . set ( { name, email } ) . where ( eq ( users . id , user . id ) ) ,
240- logActivity ( userWithTeam ?. teamId , user . id , ActivityType . UPDATE_ACCOUNT ) ,
260+ ...( skipAccountUpdate
261+ ? [ ]
262+ : [ db . update ( users ) . set ( { name, email } ) . where ( eq ( users . id , user . id ) ) ] ) ,
263+ ...( skipActivityLog
264+ ? [ ]
265+ : [ logActivity ( userWithTeam ?. teamId , user . id , activityType ) ] ) ,
241266 ] ) ;
242267
243268 return { name, success : "Account updated successfully." } ;
@@ -321,7 +346,10 @@ export const inviteTeamMember = validatedActionWithUser(
321346 )
322347 . limit ( 1 ) ;
323348
324- if ( existingInvitation . length > 0 ) {
349+ if (
350+ existingInvitation . length > 0 &&
351+ ! ( await isFaultActive ( "duplicate-pending-invite-allowed" ) )
352+ ) {
325353 return { error : "An invitation has already been sent to this email" } ;
326354 }
327355
0 commit comments