1
0

profile.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Import modules. */
  2. import { defineStore } from 'pinia'
  3. /**
  4. * Profile Store
  5. */
  6. export const useProfileStore = defineStore('profile', {
  7. state: () => ({
  8. /* Initialize session. */
  9. _session: null,
  10. _profiles: null,
  11. }),
  12. getters: {
  13. session(_state) {
  14. return _state._session || null
  15. },
  16. sessionid(_state) {
  17. return _state._session?.id || null
  18. },
  19. challenge(_state) {
  20. return _state._session?.challenge || null
  21. },
  22. profiles(_state) {
  23. return _state._profiles || null
  24. },
  25. },
  26. actions: {
  27. init () {
  28. console.log('Initializing Profiles...')
  29. },
  30. async initSession () {
  31. console.log('INIT SESSION (before):', this._session)
  32. /* Check for existing session. */
  33. if (this._session) {
  34. return this._session
  35. }
  36. /* Request new session. */
  37. const session = await $fetch('/api/newSession')
  38. console.log('INIT SESSION (after fetch):', session)
  39. /* Set session. */
  40. this._setSession(session)
  41. /* Return session. */
  42. return session
  43. },
  44. deleteSession() {
  45. /* Set session. */
  46. this._setSession(null)
  47. },
  48. saveSession(_session) {
  49. /* Set session. */
  50. this._setSession(_session)
  51. },
  52. /**
  53. * Set Session
  54. *
  55. * @param {Object} _session Save session details.
  56. */
  57. _setSession (_session) {
  58. /* Set session. */
  59. this._session = _session
  60. console.log('SET SESSION', this._session)
  61. },
  62. /**
  63. * Set API Key
  64. *
  65. * @param {Object} _key Information for the Exchange's API key.
  66. */
  67. setApiKey (_key: Object) {
  68. /* Set session. */
  69. this._apiKeys[_key.exchangeid] = _key
  70. console.log('SET API KEY', this._apiKeys)
  71. },
  72. },
  73. })