gwtpgwt-platformgwt-places

GWTP how to execute code on application initialization/start


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.


Solution

  • 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.