fix: session auth issues

This commit is contained in:
swve 2024-05-27 20:58:32 +02:00
parent 1708b36818
commit 08cc97f557
70 changed files with 607 additions and 427 deletions

View file

@ -32,7 +32,7 @@ export const RequestBodyWithAuthHeader = (
headers: HeadersConfig,
redirect: 'follow',
credentials: 'include',
body: data,
body: (method === 'POST' || method === 'PUT') ? JSON.stringify(data) : null,
// Next.js
next: next,
}
@ -41,6 +41,27 @@ export const RequestBodyWithAuthHeader = (
export const RequestBodyForm = (method: string, data: any, next: any) => {
let HeadersConfig = new Headers({})
let options: any = {
method: method,
headers: HeadersConfig,
redirect: 'follow',
credentials: 'include',
body: (method === 'POST' || method === 'PUT') ? JSON.stringify(data) : null,
// Next.js
next: next,
}
return options
}
export const RequestBodyFormWithAuthHeader = (
method: string,
data: any,
next: any,
access_token: string
) => {
let HeadersConfig = new Headers({
Authorization: `Bearer ${access_token}`,
})
let options: any = {
method: method,
headers: HeadersConfig,
@ -53,9 +74,13 @@ export const RequestBodyForm = (method: string, data: any, next: any) => {
return options
}
export const swrFetcher = async (url: string) => {
export const swrFetcher = async (url: string, token?: string) => {
// Create the request options
let HeadersConfig = new Headers({ 'Content-Type': 'application/json' })
let HeadersConfig = new Headers(
token
? { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` }
: { 'Content-Type': 'application/json' }
)
let options: any = {
method: 'GET',
headers: HeadersConfig,