@@ -104,6 +104,7 @@ type PopupKey =
104104 | "updatePassword"
105105 | "removeGoogleAuth"
106106 | "removeGithubAuth"
107+ | "removePasswordAuth"
107108 | "addPasswordAuth"
108109 | "deleteAccount"
109110 | "resetAccount"
@@ -133,6 +134,7 @@ const list: Record<PopupKey, SimpleModal | undefined> = {
133134 updatePassword : undefined ,
134135 removeGoogleAuth : undefined ,
135136 removeGithubAuth : undefined ,
137+ removePasswordAuth : undefined ,
136138 addPasswordAuth : undefined ,
137139 deleteAccount : undefined ,
138140 resetAccount : undefined ,
@@ -301,13 +303,8 @@ class SimpleModal {
301303 } )
302304 ) ;
303305 } else if ( input . type === "checkbox" ) {
304- let html = `
305- <input
306- id="${ id } "
307- type="checkbox"
308- class="${ input . hidden ? "hidden" : "" } "
309- ${ input . initVal ? 'checked="checked"' : "" } >
310- ` ;
306+ let html = buildTag ( { tagname, classes, attributes } ) ;
307+
311308 if ( input . description !== undefined ) {
312309 html += `<span>${ input . description } </span>` ;
313310 }
@@ -797,6 +794,54 @@ list.removeGithubAuth = new SimpleModal({
797794 } ,
798795} ) ;
799796
797+ list . removePasswordAuth = new SimpleModal ( {
798+ id : "removePaswordAuth" ,
799+ title : "Remove Password authentication" ,
800+ inputs : [
801+ {
802+ type : "checkbox" ,
803+ label : `I understand I will lose access to my Monkeytype account if my Google/GitHub account is lost or disabled.` ,
804+ } ,
805+ ] ,
806+ onlineOnly : true ,
807+ buttonText : "reauthenticate to remove" ,
808+ execFn : async ( _thisPopup ) : Promise < ExecReturn > => {
809+ const reauth = await reauthenticate ( {
810+ excludeMethod : "password" ,
811+ } ) ;
812+ if ( reauth . status !== 1 ) {
813+ return {
814+ status : reauth . status ,
815+ message : reauth . message ,
816+ } ;
817+ }
818+
819+ try {
820+ await unlink ( reauth . user , "password" ) ;
821+ } catch ( e ) {
822+ const message = createErrorMessage (
823+ e ,
824+ "Failed to remove password authentication"
825+ ) ;
826+ return {
827+ status : - 1 ,
828+ message,
829+ } ;
830+ }
831+
832+ Settings . updateAuthSections ( ) ;
833+
834+ reloadAfter ( 3 ) ;
835+ return {
836+ status : 1 ,
837+ message : "Password authentication removed" ,
838+ } ;
839+ } ,
840+ beforeInitFn : ( ) : void => {
841+ if ( ! isAuthenticated ( ) ) return ;
842+ } ,
843+ } ) ;
844+
800845list . updateName = new SimpleModal ( {
801846 id : "updateName" ,
802847 title : "Update name" ,
@@ -1621,6 +1666,7 @@ list.updateCustomTheme = new SimpleModal({
16211666 type : "checkbox" ,
16221667 initVal : false ,
16231668 label : "Update custom theme to current colors" ,
1669+ optional : true ,
16241670 } ,
16251671 ] ,
16261672 buttonText : "update" ,
@@ -1766,6 +1812,7 @@ list.devGenerateData = new SimpleModal({
17661812 label : "create user" ,
17671813 description :
17681814 "if checked, user will be created with {username}@example.com and password: password" ,
1815+ optional : true ,
17691816 } ,
17701817 {
17711818 type : "date" ,
@@ -1865,6 +1912,9 @@ $(".pageSettings #removeGoogleAuth").on("click", () => {
18651912$ ( ".pageSettings #removeGithubAuth" ) . on ( "click" , ( ) => {
18661913 showPopup ( "removeGithubAuth" ) ;
18671914} ) ;
1915+ $ ( ".pageSettings #removePasswordAuth" ) . on ( "click" , ( ) => {
1916+ showPopup ( "removePasswordAuth" ) ;
1917+ } ) ;
18681918
18691919$ ( "#resetSettingsButton" ) . on ( "click" , ( ) => {
18701920 showPopup ( "resetSettings" ) ;
0 commit comments