Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apiHeader not updated after login #26

Open
athasamid opened this issue Mar 4, 2019 · 0 comments
Open

apiHeader not updated after login #26

athasamid opened this issue Mar 4, 2019 · 0 comments

Comments

@athasamid
Copy link

athasamid commented Mar 4, 2019

Hi, I am using your architecture
I got some error when user success login, I save the token from response and use it as header
I've already save it to preference but the apiHeaders.token not updated it and still null

Here my login presenter
`override fun doLogin(nrp: String, password: String) {
interactor?.let {
compositeDisposable.add(
it.doLogin(LoginRequest.ServerLoginRequest(username = nrp, password = password))
.compose(schedulerProvider.ioToMainObservableScheduler())
.subscribe({res ->
getView()?.let {v ->
v.loginSuccess()
}

                    interactor?.setToken("${res.tokenType} ${res.accessToken}").let {
                        loadUserInfo()
                    }

                }, {err ->
                    val anError = err as ANError
                    if (anError.errorCode == 401) {
                        getView()?.loginFailure("NRP atau password tidak sesuai")
                    }
                })
        )
    }
}

override fun loadUserInfo() {
    interactor?.let {
        compositeDisposable.add(
            it.loadUser()
                .compose(schedulerProvider.ioToMainObservableScheduler())
                .subscribe ({d ->
                    interactor?.setUserInfo(d.data)
                    getView()?.userInfoSuccess()
                }, {err ->

                })
        )
    }
}`

LoginInteractor
`override fun doLogin(request: LoginRequest.ServerLoginRequest): Observable = apiHelper.performServerLogin(request)

override fun loadUser(): Observable<DataUserResponse> = apiHelper.performInfoUser()

override fun sendToken(request: LoginRequest.UpdateFcmRequest): Observable<DefaultResponse> = apiHelper.performUpdateFcm(request)

override fun setToken(token: String) {
    preferenceHelper.setToken(token)
}`

AppModule.kt
@Provides @Singleton internal fun provideProtectedApiHeader(@AcceptHeader accept: String, preferenceHelper: PreferenceHelper) : ApiHeader.ProtectedApiHeader = ApiHeader.ProtectedApiHeader(accept = accept, token = preferenceHelper.getToken())

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant