feat(client-side): create story middleware
redirect users to the login page if a story is restricted and they're not logged in
This commit is contained in:
		
							parent
							
								
									17e9d0cbf8
								
							
						
					
					
						commit
						fe7c452231
					
				
							
								
								
									
										15
									
								
								lib/client/middleware.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								lib/client/middleware.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| import { SingleChapterResult } from "./types/slightlyDifferentStory"; | ||||
| 
 | ||||
| export const storyMiddleware = defineNuxtRouteMiddleware(async (to, from) => { | ||||
| 	const { getSession } = useAuth(); | ||||
| 	await getSession({ force: true }); | ||||
| 	const { data } = useAuth(); | ||||
| 	console.log("to n from", to, from, data); | ||||
| 	const { data: story, error } = await useApiFetch<SingleChapterResult>( | ||||
| 		to.path, | ||||
| 	); | ||||
| 	console.log("fns", story, error); | ||||
| 	if (!data?.value?.user && story.value?.currentChapter.loggedInOnly) { | ||||
| 		return navigateTo("/login"); | ||||
| 	} | ||||
| }); | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user