logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

oauth.js (1559B)


  1. const oauth = {
  2. state: {
  3. clientId: false,
  4. clientSecret: false,
  5. /* App token is authentication for app without any user, used mostly for
  6. * MastoAPI's registration of new users, stored so that we can fall back to
  7. * it on logout
  8. */
  9. appToken: false,
  10. /* User token is authentication for app with user, this is for every calls
  11. * that need authorized user to be successful (i.e. posting, liking etc)
  12. */
  13. userToken: false
  14. },
  15. mutations: {
  16. setClientData (state, { clientId, clientSecret }) {
  17. state.clientId = clientId
  18. state.clientSecret = clientSecret
  19. },
  20. setAppToken (state, token) {
  21. state.appToken = token
  22. },
  23. setToken (state, token) {
  24. state.userToken = token
  25. },
  26. clearToken (state) {
  27. state.userToken = false
  28. // state.token is userToken with older name, coming from persistent state
  29. // let's clear it as well, since it is being used as a fallback of state.userToken
  30. delete state.token
  31. }
  32. },
  33. getters: {
  34. getToken: state => () => {
  35. // state.token is userToken with older name, coming from persistent state
  36. // added here for smoother transition, otherwise user will be logged out
  37. return state.userToken || state.token || state.appToken
  38. },
  39. getUserToken: state => () => {
  40. // state.token is userToken with older name, coming from persistent state
  41. // added here for smoother transition, otherwise user will be logged out
  42. return state.userToken || state.token
  43. }
  44. }
  45. }
  46. export default oauth