Commit 29c7b39e authored by tom's avatar tom

call api from client for user profile data

parent 82984260
......@@ -37,6 +37,7 @@ function makePolicyMap() {
'connect-src': [
KEY_WORDS.SELF,
...MAIN_DOMAINS,
// webpack hmr in safari doesn't recognize localhost as 'self' for some reason
isDev ? 'ws://localhost:3000/_next/webpack-hmr' : '',
......
......@@ -13,6 +13,7 @@ export interface ErrorType<T> {
interface Params {
method?: RequestInit['method'];
body?: Record<string, unknown>;
credentials?: RequestCredentials;
}
export default function useFetch() {
......
import { useQuery } from '@tanstack/react-query';
import { useRouter } from 'next/router';
import type { UserInfo } from 'types/api/account';
......@@ -13,10 +14,14 @@ interface Error {
export default function useFetchProfileInfo() {
const fetch = useFetch();
const router = useRouter();
const url = new URL(`/${ router.query.network_type }/${ router.query.network_sub_type }/api/account/v1/user/info`, 'https://blockscout.com');
return useQuery<unknown, Error, UserInfo>([ 'profile' ], async() => {
return fetch('/api/account/profile');
return fetch(url.toString(), { credentials: 'include' });
}, {
refetchOnMount: false,
enabled: Boolean(router.query.network_type && router.query.network_sub_type),
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment