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

Rewrite authentication logic with the API store #373

Merged
merged 29 commits into from
Feb 23, 2020

Conversation

carlobeltrame
Copy link
Member

@carlobeltrame carlobeltrame commented Feb 19, 2020

Fixes #355, fixes #318, fixes part of #359, fixes #364

  • Cleans up all authentication logic and rewrites it using the API store in a much more readable way
  • Adds a new API store function href that can be used to get the URI of a related entity without fetching it first
  • Renames loaded Promises to load
  • Fixes several bugs to do with reloading, posting or patching objects and the returned load Promises (and write tests for them)
  • Renames the LoginController and all its related uses to AuthController and similar
  • self links returned from a storeValueProxy (api.get() etc.) are now all absolute URIs (including the host), but in the store we still keep them as normalized, relative URIs, for easier debugging
  • Adds fancy spinners to the login and logout buttons ✨

The main change is the simpler authentication logic. When before the logic was this:

  async function login (username, password) {
    return axios.post(process.env.VUE_APP_ROOT_API + '/login/login', { username: username, password: password })
      .then(resp => {
        if (resp.data.user !== 'guest') {
          this.loginSuccess()
          return true
        } else {
          return false
        }
      })
  },

now the equivalent code is written like this:

async function login (username, password) {
  const url = await href(get().auth(), 'login')
  return post(url, { username: username, password: password }).then(() => refreshLoginStatus())
}

This allows for simpler use of reload in scenarios where we don't know
whether or not we already have an entity in the Vuex store:

await reload(get().camps())._meta.loaded

instead of the following, which is more complicated:

await reload(await href(get(), 'camps'))._meta.loaded

or the following, which loads the entity twice:

await reload(await get().camps()._meta.loaded)._meta.loaded
…ementation, add logout spinner and remove logout view
@carlobeltrame carlobeltrame requested review from manuelmeister, pmattmann and usu and removed request for manuelmeister February 19, 2020 21:40
@carlobeltrame carlobeltrame merged commit 1370a19 into ecamp:devel Feb 23, 2020
@carlobeltrame carlobeltrame deleted the auth-with-vuex branch February 23, 2020 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants