1

I would like to execute asynchronous call to the server when the application starts (have been loaded in users browser).

To communicate with server I use RestyGWT.

On application start I wanna call server to check is user logged in (is his cookie/token is still valid)? If token is still valid, I would like to redirect user to page for logged in users. If not I would like to redirect to login page

I would like to work this also for inside client app urls, for example: http://localhost:8080/cms/#/admin. When I enter this url from inside app it work. When I enters this url it redirect me to default page.

Please help.

Here is my service execution code:

service.isCurrentUserLoggedIn(new MethodCallback<Boolean>() {
    @Override
    public void onFailure(Method method, Throwable exception) {
    MaterialToast.fireToast("Fail to check is current user logged in " + method + " " + exception.getLocalizedMessage());
    }

    @Override
    public void onSuccess(Method method, Boolean response) {
    currentUser.setLoggedIn(response);
    getView().setLoginButtonVisbility(response);
    }
});

I've done this in AppPresenter in class constructor, but this is I think wrong.

masterdany88
  • 5,041
  • 11
  • 58
  • 132

2 Answers2

0

I think it should be enough if you move out of the constructor and into the onBind() method. Though I'm assuming this is in your presenter revealed in root and your other presenters are revealed in the root presenters slots.

The Gilbert Arenas Dagger
  • 12,071
  • 13
  • 66
  • 80
0

The solution is to create own Bootstrapper class that implements com.gwtplatform.mvp.client.Bootstrapper

and inside this class implement method void onBootstrap() where I execute service.isCurrentUserLoggedIn(new MethodCallback<Boolean>() {}) and then base on answer result, redirect to login or current place.

Here is official documentation.

masterdany88
  • 5,041
  • 11
  • 58
  • 132