@@ -8,8 +8,14 @@ export interface AuthenticatorEvents {
88
99 /**
1010 * This event gets called when the login process completes without error.
11+ * The event handler must return a Promise that resolves to a boolean value.
12+ * When this value is true, the user session will be started.
13+ * Otherwise, the user will be returned to the greeter.
14+ * This allows for custom handling of the authentication result or adding another form on top.
15+ * The AuthenticationFailure event is not called afterwards, so update the UI accordingly if
16+ * false is returned.
1117 */
12- authenticationComplete : ( ) => void ;
18+ authenticationComplete : ( ) => Promise < boolean > ;
1319
1420 /**
1521 * This event gets called when the login process fails due to an authentication failure (wrong username or password).
@@ -103,27 +109,31 @@ export class Authenticator {
103109 } ) ;
104110
105111 // This event gets called when LightDM says the authentication was successful and a session should be started
106- lightdm . authentication_complete . connect ( ( ) => {
112+ lightdm . authentication_complete . connect ( async ( ) => {
107113 try {
108- this . _authenticating = false ;
109114 console . log ( "LightDM authentication complete. Checking results..." ) ;
110- if ( lightdm . is_authenticated ) {
111- this . _authenticated = true ;
112- console . log ( "LightDM authentication successful! Starting session..." ) ;
115+ if ( ! lightdm . is_authenticated ) {
116+ this . _authenticating = false ;
117+ console . log ( "LightDM authentication failed. User not found or password incorrect." ) ;
118+ this . _stopAuthentication ( ) ;
113119 if ( this . _authEvents ) {
114- this . _authEvents . authenticationComplete ( ) ;
120+ this . _authEvents . authenticationFailure ( ) ;
115121 }
122+ return ;
123+ }
124+ this . _authenticated = true ;
125+ this . _authenticating = false ;
126+ console . log ( "LightDM authentication successful! Starting session..." ) ;
127+ const eventResult = ( this . _authEvents ) ? await this . _authEvents . authenticationComplete ( ) : Promise . resolve ( true ) ;
128+ if ( eventResult ) {
116129 lightdm . start_session ( this . _session ?? null ) ;
117130 }
118131 else {
119- console . log ( "LightDM authentication failed. User not found or password incorrect." ) ;
120132 this . _stopAuthentication ( ) ;
121- if ( this . _authEvents ) {
122- this . _authEvents . authenticationFailure ( ) ;
123- }
124133 }
125134 }
126135 catch ( err ) {
136+ this . _authenticating = false ;
127137 window . ui . setDebugInfo ( String ( err ) ) ;
128138 if ( this . _authEvents ) {
129139 this . _authEvents . errorMessage ( String ( err ) ) ;
0 commit comments