Gtk-rs: Best practice after showing dashboard after login?

Hello

I currently have a Gtk-rs application where the user gets a window with a login-form. When the authentication fails I show a label with "Wrong password" below the login-form. If the login works I want to show the dashboard for the user.

Currently I have achieved this by making two separate windows. One for the login and one for the dashboard. When the login is successful I close the login-window and show the window with the dashboard.

This works but I am wondering if this is the recommended/best practice way. Is it also possible to clear the content of the login-window and show the dashboard in that window? Would that be better?

    // Window with login-form
    let auth_window = gtk::ApplicationWindow::builder()
    //...
    
    // Window with user-dashboard (accessible after login)
    let dashboard_window = gtk::ApplicationWindow::builder()
    //...

    
    // Present login form
    auth_window.present();

    login_button.connect_clicked(move | _button| {
        let weak_label = label.downgrade();
        let weak_dashboard_window = dashboard_window.downgrade();
        let weak_auth_window = auth_window.downgrade();
        
        let username = username_input.text().as_str().to_string();
        let password = password_input.text().as_str().to_string();
        glib::MainContext::default().spawn_local(async move {
            match server::login(username, password).await {
                true => {
                    // Authentication successful -> Hide login-window and show window with
                    // user-dashboard
                    weak_dashboard_window.upgrade().unwrap().present();
                    weak_auth_window.upgrade().unwrap().close();

                },
                // Authentication failed -> Show label with "Wrong password" in login-window
                false => weak_label.upgrade().unwrap().set_text("Fout wachtwoord."),
            };
        });
    });

Thanks!

this is a common way to do it. there's nothing wrong about it. another common way is to only create the dashboard window when the login is successful. either method is ok, it's not significantly different really.

it is of course possible, but it's more complicated to do dynamic UI, and you gain nothing in return. it's not worth the effort.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.