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
|
|
@ -4,6 +4,7 @@ import { getAPIUrl } from '@services/config/config'
|
|||
import { swrFetcher } from '@services/utils/ts/requests'
|
||||
import React, { createContext, useContext, useEffect, useReducer } from 'react'
|
||||
import useSWR from 'swr'
|
||||
import { useLHSession } from '@components/Contexts/LHSessionContext'
|
||||
|
||||
export const CourseContext = createContext(null) as any
|
||||
export const CourseDispatchContext = createContext(null) as any
|
||||
|
|
@ -15,9 +16,11 @@ export function CourseProvider({
|
|||
children: React.ReactNode
|
||||
courseuuid: string
|
||||
}) {
|
||||
const session = useLHSession() as any;
|
||||
const access_token = session?.data?.tokens?.access_token;
|
||||
const { data: courseStructureData } = useSWR(
|
||||
`${getAPIUrl()}courses/${courseuuid}/meta`,
|
||||
swrFetcher
|
||||
(url) => swrFetcher(url, access_token)
|
||||
)
|
||||
const [courseStructure, dispatchCourseStructure] = useReducer(courseReducer, {
|
||||
courseStructure: courseStructureData ? courseStructureData : {},
|
||||
|
|
@ -33,7 +36,7 @@ export function CourseProvider({
|
|||
payload: courseStructureData,
|
||||
})
|
||||
}
|
||||
}, [courseStructureData])
|
||||
}, [courseStructureData,session])
|
||||
|
||||
if (!courseStructureData) return <PageLoading></PageLoading>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue