refactor(client-side): use to parameter to check for current url + associated params
				
					
				
			This commit is contained in:
		
							parent
							
								
									8747d6b604
								
							
						
					
					
						commit
						a65590d47e
					
				| @ -26,8 +26,7 @@ export const storyMiddleware = defineNuxtRouteMiddleware(async (to, from) => { | |||||||
| 
 | 
 | ||||||
| export const storyEditMiddleware = defineNuxtRouteMiddleware(async (to, from) => { | export const storyEditMiddleware = defineNuxtRouteMiddleware(async (to, from) => { | ||||||
| 	const { data: curU } = useAuth(); | 	const { data: curU } = useAuth(); | ||||||
| 	const rtr = useRoute(); | 	const { data: storyInfo } = await useApiFetch<({ chapters: (IChapter & { text: string })[] } & IStory) | null>(`/story/${to.params.id}/full`); | ||||||
| 	const { data: storyInfo } = await useApiFetch<({ chapters: (IChapter & { text: string })[] } & IStory) | null>(`/story/${rtr.params.id}/full`); |  | ||||||
| 	if (!storyInfo.value) show404(); | 	if (!storyInfo.value) show404(); | ||||||
| 	if (curU.value?.user?._id !== (storyInfo.value?.author as IUser)._id && curU.value?.user?._id !== (storyInfo.value?.coAuthor as IUser)?._id) { | 	if (curU.value?.user?._id !== (storyInfo.value?.author as IUser)._id && curU.value?.user?._id !== (storyInfo.value?.coAuthor as IUser)?._id) { | ||||||
| 		return showError({ | 		return showError({ | ||||||
| @ -38,8 +37,7 @@ export const storyEditMiddleware = defineNuxtRouteMiddleware(async (to, from) => | |||||||
| }); | }); | ||||||
| export const draftEditMiddleware = defineNuxtRouteMiddleware(async (to, from) => { | export const draftEditMiddleware = defineNuxtRouteMiddleware(async (to, from) => { | ||||||
| 	const { data: curU } = useAuth(); | 	const { data: curU } = useAuth(); | ||||||
| 	const rtr = useRoute(); | 	const { data: storyInfo } = await useApiFetch<IDraft | null>(`/draft/${to.params.id}`); | ||||||
| 	const { data: storyInfo } = await useApiFetch<IDraft | null>(`/draft/${rtr.params.id}`); |  | ||||||
| 	if (!storyInfo.value) show404(); | 	if (!storyInfo.value) show404(); | ||||||
| 	if (curU.value?.user?._id !== (storyInfo.value?.author as IUser)._id && curU.value?.user?._id !== (storyInfo.value?.coAuthor as IUser)?._id) { | 	if (curU.value?.user?._id !== (storyInfo.value?.author as IUser)._id && curU.value?.user?._id !== (storyInfo.value?.coAuthor as IUser)?._id) { | ||||||
| 		return showError({ | 		return showError({ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user