All files / app/(dynamic) layout.tsx

100% Statements 11/11
100% Branches 2/2
100% Functions 4/4
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38                  102x                     83x 102x   102x 80x 80x 22x 22x     58x   80x     102x    
'use client'
import { useEffect } from 'react'
import { Provider } from 'react-redux'
import { hasSession } from '../../services/auth/session'
import { logout, refreshToken } from '../../store/auth/auth'
import { useAppDispatch } from '../../store/hooks'
import { store } from '../../store/store'
 
export default function RootLayout({ children }: { children: React.ReactNode }) {
	return (
		<Provider store={store}>
			<Auth>{children}</Auth>
		</Provider>
	)
}
 
type AuthProps = {
	children: React.ReactNode
}
 
const Auth: React.FC<AuthProps> = ({ children }) => {
	const dispatch = useAppDispatch()
 
	useEffect(() => {
		const checkAuthenticated = async () => {
			if (!hasSession()) {
				dispatch(logout())
				return null
			}
 
			await dispatch(refreshToken({ ignoreExpireCheck: false }))
		}
		checkAuthenticated()
	}, []) // eslint-disable-line react-hooks/exhaustive-deps
 
	return <>{children}</>
}