init.server.ts 866 B

1234567891011121314151617181920212223242526
  1. import {defineNuxtPlugin} from "nuxt/app";
  2. import {useProfileAccessStore} from "~/store/profile/access";
  3. export default defineNuxtPlugin(async ({$pinia, ssrContext}) => {
  4. const profileAccessStore = useProfileAccessStore($pinia)
  5. const arraysCookies = ssrContext?.req?.headers.cookie?.split('; ').map((a:string) => a.split('='))
  6. if(arraysCookies) {
  7. const cookies = Object.fromEntries(arraysCookies)
  8. profileAccessStore.$patch({
  9. bearer: cookies['BEARER'],
  10. id: cookies['AccessId']
  11. })
  12. const data = await $fetch('/api/my_profile', {
  13. baseURL: 'http://nginx_new',
  14. headers: {
  15. 'x-accessid' : profileAccessStore.id,
  16. 'Authorization' : 'BEARER ' + profileAccessStore.bearer
  17. }
  18. })
  19. profileAccessStore.setProfile(data)
  20. }
  21. })