mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
fix: session auth issues
This commit is contained in:
parent
1708b36818
commit
08cc97f557
70 changed files with 607 additions and 427 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue