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

@ -12,6 +12,7 @@ import {
Video,
X,
} from 'lucide-react'
import { useLHSession } from '@components/Contexts/LHSessionContext'
import Link from 'next/link'
import { useRouter } from 'next/navigation'
import React from 'react'
@ -32,6 +33,8 @@ interface ModifiedActivityInterface {
function ActivityElement(props: ActivitiyElementProps) {
const router = useRouter()
const session = useLHSession() as any;
const access_token = session?.data?.tokens?.access_token;
const [modifiedActivity, setModifiedActivity] = React.useState<
ModifiedActivityInterface | undefined
>(undefined)
@ -41,7 +44,7 @@ function ActivityElement(props: ActivitiyElementProps) {
const activityUUID = props.activity.activity_uuid
async function deleteActivityUI() {
await deleteActivity(props.activity.activity_uuid)
await deleteActivity(props.activity.activity_uuid,access_token)
mutate(`${getAPIUrl()}courses/${props.course_uuid}/meta`)
await revalidateTags(['courses'], props.orgslug)
router.refresh()
@ -60,7 +63,7 @@ function ActivityElement(props: ActivitiyElementProps) {
content: props.activity.content,
}
await updateActivity(modifiedActivityCopy, activityUUID)
await updateActivity(modifiedActivityCopy, activityUUID,access_token)
mutate(`${getAPIUrl()}courses/${props.course_uuid}/meta`)
await revalidateTags(['courses'], props.orgslug)
router.refresh()

View file

@ -16,6 +16,7 @@ import { revalidateTags } from '@services/utils/ts/requests'
import { useRouter } from 'next/navigation'
import { getAPIUrl } from '@services/config/config'
import { mutate } from 'swr'
import { useLHSession } from '@components/Contexts/LHSessionContext'
type ChapterElementProps = {
chapter: any
@ -31,6 +32,8 @@ interface ModifiedChapterInterface {
function ChapterElement(props: ChapterElementProps) {
const activities = props.chapter.activities || []
const session = useLHSession() as any;
const access_token = session?.data?.tokens?.access_token;
const [modifiedChapter, setModifiedChapter] = React.useState<
ModifiedChapterInterface | undefined
>(undefined)
@ -41,7 +44,7 @@ function ChapterElement(props: ChapterElementProps) {
const router = useRouter()
const deleteChapterUI = async () => {
await deleteChapter(props.chapter.id)
await deleteChapter(props.chapter.id, access_token)
mutate(`${getAPIUrl()}courses/${props.course_uuid}/meta`)
await revalidateTags(['courses'], props.orgslug)
router.refresh()
@ -53,7 +56,7 @@ function ChapterElement(props: ChapterElementProps) {
let modifiedChapterCopy = {
name: modifiedChapter.chapterName,
}
await updateChapter(chapterId, modifiedChapterCopy)
await updateChapter(chapterId, modifiedChapterCopy, access_token)
mutate(`${getAPIUrl()}courses/${props.course_uuid}/meta`)
await revalidateTags(['courses'], props.orgslug)
router.refresh()