Fix share page permissions
This commit is contained in:
1 parent
f41c0221c4
commit
9d477b25b4
7 files changed
+47
-29
No files matched your search
@@ -1,22 +1,18 @@
|
||||
import { setShare, setShareToken, useApp } from '@/store/app';
|
||||
import { setShareData } from '@/store/app';
|
||||
import { useApi } from '../useApi';
|
||||
|
||||
const selector = state => state.share;
|
||||
|
||||
export function useShareTokenQuery(slug: string) {
|
||||
const share = useApp(selector);
|
||||
const { get, useQuery } = useApi();
|
||||
const query = useQuery({
|
||||
queryKey: ['share', slug],
|
||||
queryFn: async () => {
|
||||
const data = await get(`/share/${slug}`);
|
||||
|
||||
setShare(data);
|
||||
setShareToken({ token: data?.token });
|
||||
setShareData(data, { token: data?.token });
|
||||
|
||||
return data;
|
||||
},
|
||||
});
|
||||
|
||||
return { share, ...query };
|
||||
return { share: query.data, ...query };
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import { useMutation, useQuery } from '@tanstack/react-query';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { useCallback } from 'react';
|
||||
import { getClientAuthToken } from '@/lib/client';
|
||||
import { SHARE_TOKEN_HEADER } from '@/lib/constants';
|
||||
import { SHARE_CONTEXT_HEADER, SHARE_TOKEN_HEADER } from '@/lib/constants';
|
||||
import { type FetchResponse, httpDelete, httpGet, httpPost, httpPut } from '@/lib/fetch';
|
||||
import { useApp } from '@/store/app';
|
||||
|
||||
@@ -18,10 +19,17 @@ async function handleResponse(res: FetchResponse): Promise<any> {
|
||||
|
||||
export function useApi() {
|
||||
const shareToken = useApp(selector);
|
||||
const pathname = usePathname();
|
||||
const isSharePath = pathname?.startsWith('/share');
|
||||
|
||||
const shareHeaders =
|
||||
isSharePath && shareToken?.token
|
||||
? { [SHARE_TOKEN_HEADER]: shareToken.token, [SHARE_CONTEXT_HEADER]: '1' }
|
||||
: {};
|
||||
|
||||
const defaultHeaders = {
|
||||
authorization: `Bearer ${getClientAuthToken()}`,
|
||||
[SHARE_TOKEN_HEADER]: shareToken?.token,
|
||||
...shareHeaders,
|
||||
};
|
||||
const basePath = process.env.basePath;
|
||||
|
||||
|
||||
Reference in new issue
Block a user