Skip to content

Commit

Permalink
Fixing the external api
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiří Procházka committed Oct 27, 2023
1 parent 3c8efc9 commit f5fca83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/runtime/composables/useCookiesAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { navigateTo, useRequestEvent, useRequestHeaders, useRuntimeConfig, useRo
import { RuntimeConfig } from "@nuxt/schema"
import { RouteLocationNormalizedLoaded } from "#vue-router"

const credential = "include" as const

export const useCookiesAuth = () => {
const event = useRequestEvent()
const header = useRequestHeaders()
Expand All @@ -16,6 +18,7 @@ export const useCookiesAuth = () => {
retryStatusCodes: [401],
retry: 1,
baseURL: config.public.cookiesAuth.apiBaseUrl,
credentials: credential,
onResponseError: async (context: FetchContext) => {
if (context.response?.status === 401) {
const res = await $fetch.raw(config.public.cookiesAuth.refreshTokenUrl, {
Expand All @@ -24,14 +27,15 @@ export const useCookiesAuth = () => {
headers: {
cookie: header.cookie
},
credentials: credential,
onResponseError: refreshTokenOnResponseErrorHandler
})

const cookies = (res.headers.get("set-cookie") || "").split(",")

context.options.headers = {
...context.options.headers,
cookie: cookies.map((c) => c.split(";")[0]).join(",")
cookie: cookies.map((c) => c.split(";")[0]).join(";")
}

if (event) {
Expand Down

0 comments on commit f5fca83

Please sign in to comment.