Project

General

Profile

Is it valid to have multiple AuthWidget instances in one Wt application?

Added by Ali Ali 7 days ago

Hi everyone,

I’m currently using Wt::Auth::AuthWidget in my application for user authentication.
At the moment, I create a single AuthWidget instance inside my main application class and access it from other widgets (like my navigation bar or some CTA buttons) through:

auto app = dynamic_cast<MyApp*>(Wt::WApplication::instance());
auto auth = app->authWidget();

However, in some situations, I feel it might be more convenient to have separate AuthWidget instances for each section — for example, one in the navbar, one in a sidebar, and one in a modal dialog.

Before doing that, I’d like to make sure:
👉 Is it valid or safe to create multiple AuthWidget objects in the same WApplication?
Do they share the same Session and Login properly, or could that lead to inconsistent behavior or crashes?

I also noticed that sometimes I need to pass ownership of the AuthWidget (as a unique_ptr) to other Wt widgets, which makes it harder to keep a single shared instance.

What’s the recommended pattern for handling this — should I always have only one AuthWidget and connect other widgets through signals, or is it okay to create multiple ones if they all use the same Session?

Thanks in advance for any clarification or best practices!