From e4ca52d58d3be80b92e952160bb039e2977609dd Mon Sep 17 00:00:00 2001 From: Alex Bourreau <7023229+TTalex@users.noreply.github.com> Date: Tue, 15 Oct 2024 23:25:43 +0200 Subject: [PATCH] feat(SignIn): parse and use username from access_token on signin, allows usage of emails to login (#956) Co-authored-by: Raphael Odini --- src/store.js | 4 ++-- src/utils.js | 8 ++++++++ src/views/SignIn.vue | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/store.js b/src/store.js index bae69ef551..aaf6b5339d 100644 --- a/src/store.js +++ b/src/store.js @@ -49,8 +49,8 @@ export const useAppStore = defineStore('app', { } }, actions: { - signIn(username, token) { - this.user.username = username + signIn(token) { + this.user.username = utils.getOFFUsernameFromAuthToken(token) this.user.token = token }, signOut() { diff --git a/src/utils.js b/src/utils.js index 10b609b103..429d4b88b1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -164,6 +164,13 @@ function dateType(dateString) { return null } +/** + * OFF auth token format: 'username__uuid' + */ +function getOFFUsernameFromAuthToken(token) { + return token.split("__")[0] +} + function getCategoryName(categoryId) { let category = CategoryTags.find(ct => ct.id === categoryId) return category ? category.name : categoryId @@ -372,6 +379,7 @@ export default { offDateTime, prettyRelativeDateTime, dateType, + getOFFUsernameFromAuthToken, getCategoryName, getLocaleCategoryTags, getLocaleCategoryTag, diff --git a/src/views/SignIn.vue b/src/views/SignIn.vue index 33f0fd9734..b7d74b1702 100644 --- a/src/views/SignIn.vue +++ b/src/views/SignIn.vue @@ -74,7 +74,7 @@ export default { .signIn(this.signinForm.username.toLowerCase().trim(), this.signinForm.password) .then((data) => { if (data['access_token']) { - this.appStore.signIn(this.signinForm.username.toLowerCase().trim(), data['access_token']) + this.appStore.signIn(data['access_token']) this.done() } else { alert(this.$t('SignIn.WrongCredentials'))