Skip to content

Commit

Permalink
feat(SignIn): parse and use username from access_token on signin, all…
Browse files Browse the repository at this point in the history
…ows usage of emails to login (#956)

Co-authored-by: Raphael Odini <[email protected]>
  • Loading branch information
TTalex and raphodn authored Oct 15, 2024
1 parent d721e59 commit e4ca52d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 8 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -372,6 +379,7 @@ export default {
offDateTime,
prettyRelativeDateTime,
dateType,
getOFFUsernameFromAuthToken,
getCategoryName,
getLocaleCategoryTags,
getLocaleCategoryTag,
Expand Down
2 changes: 1 addition & 1 deletion src/views/SignIn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down

0 comments on commit e4ca52d

Please sign in to comment.