feat: use session access_tokens

This commit is contained in:
swve 2024-06-01 12:23:01 +01:00
parent 08cc97f557
commit 52f2235942
74 changed files with 413 additions and 440 deletions

View file

@ -1,6 +1,6 @@
import { getAPIUrl } from '@services/config/config'
import {
RequestBody,
RequestBodyWithAuthHeader,
errorHandling,
getResponseMetadata,
} from '@services/utils/ts/requests'
@ -10,37 +10,48 @@ import {
GET requests are called from the frontend using SWR (https://swr.vercel.app/)
*/
export async function createNewOrganization(body: any) {
export async function createNewOrganization(body: any, access_token: string) {
const result = await fetch(
`${getAPIUrl()}orgs/`,
RequestBody('POST', body, null)
RequestBodyWithAuthHeader('POST', body, null,access_token)
)
const res = await errorHandling(result)
return res
}
export async function deleteOrganizationFromBackend(org_id: any) {
export async function deleteOrganizationFromBackend(
org_id: any,
access_token: string
) {
const result = await fetch(
`${getAPIUrl()}orgs/${org_id}`,
RequestBody('DELETE', null, null)
RequestBodyWithAuthHeader('DELETE', null, null, access_token)
)
const res = await errorHandling(result)
return res
}
export async function getOrganizationContextInfo(org_slug: any, next: any) {
export async function getOrganizationContextInfo(
org_slug: any,
next: any,
access_token?: string
) {
const result = await fetch(
`${getAPIUrl()}orgs/slug/${org_slug}`,
RequestBody('GET', null, next)
RequestBodyWithAuthHeader('GET', null, next, access_token)
)
const res = await errorHandling(result)
return res
}
export async function getOrganizationContextInfoWithId(org_id: any, next: any) {
export async function getOrganizationContextInfoWithId(
org_id: any,
next: any,
access_token: string
) {
const result = await fetch(
`${getAPIUrl()}orgs/${org_id}`,
RequestBody('GET', null, next)
RequestBodyWithAuthHeader('GET', null, next, access_token)
)
const res = await errorHandling(result)
return res
@ -64,10 +75,14 @@ export async function getOrganizationContextInfoWithoutCredentials(
return res
}
export function getOrganizationContextInfoNoAsync(org_slug: any, next: any) {
export function getOrganizationContextInfoNoAsync(
org_slug: any,
next: any,
access_token: string
) {
const result = fetch(
`${getAPIUrl()}orgs/slug/${org_slug}`,
RequestBody('GET', null, next)
RequestBodyWithAuthHeader('GET', null, next, access_token)
)
return result
}
@ -75,20 +90,25 @@ export function getOrganizationContextInfoNoAsync(org_slug: any, next: any) {
export async function updateUserRole(
org_id: any,
user_id: any,
role_uuid: any
role_uuid: any,
access_token: string
) {
const result = await fetch(
`${getAPIUrl()}orgs/${org_id}/users/${user_id}/role/${role_uuid}`,
RequestBody('PUT', null, null)
RequestBodyWithAuthHeader('PUT', null, null, access_token)
)
const res = await getResponseMetadata(result)
return res
}
export async function removeUserFromOrg(org_id: any, user_id: any) {
export async function removeUserFromOrg(
org_id: any,
user_id: any,
access_token: any
) {
const result = await fetch(
`${getAPIUrl()}orgs/${org_id}/users/${user_id}`,
RequestBody('DELETE', null, null)
RequestBodyWithAuthHeader('DELETE', null, null, access_token)
)
const res = await getResponseMetadata(result)
return res