Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// get access token
const getAccessToken = async () => {
// getTokenSilently() returns a promise
try {
const token = await getTokenSilently();
setAccessToken(token);
console.log(token);
} catch (e) {
console.log(e);
}
};
getAccessToken();
// for apollo client
const httpLink = new HttpLink({
uri: "https://instagram-clone-3.herokuapp.com/v1/graphql"
});
const authLink = setContext((_, { headers }) => {
const token = accessToken;
if (token) {
return {
headers: {
...headers,
authorization: `Bearer ${token}`
}
};
} else {
return {
headers: {
...headers
function create(initialState, native) {
const httpLink = new HttpLink({
uri: 'https://api.graph.cool/simple/v1/cjh2g1fxn6gsw0108o6ud01ms', // Server URL (must be absolute)
credentials: 'same-origin', // Additional fetch() options like `credentials` or `headers`
});
const wsLink =
(process.browser || native) &&
new WebSocketLink({
uri: 'wss://subscriptions.graph.cool/v1/cjh2g1fxn6gsw0108o6ud01ms',
options: {
reconnect: true,
},
});
const link =
!process.browser && !native
? httpLink
: split(
({ query }) => {
function createApolloClient(initialState, options) {
if (!!options.getHeaders) headers = options.getHeaders();
const data = !!initialState && (typeof initialState.cartOpen != 'undefined')
? initialState
: {
cartOpen: false,
me: null,
};
const cache = new InMemoryCache().restore(data);
const client = new ApolloClient({
connectToDevTools: !!process.browser,
ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
fetch,
link: new HttpLink({
uri,
credentials: 'include',
headers,
request: operation => {
operation.setContext({
fetchOptions: {
credentials: 'include',
},
headers,
});
},
}),
cache,
resolvers: {
Mutation: {
toggleCart: (_, variables, { cache }) => {
function createApolloClient(initialState: NormalizedCacheObject) {
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
return new ApolloClient({
connectToDevTools: process.browser,
ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
link: new HttpLink({
// uri: "https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn", // Server URL (must be absolute)
uri: "http://localhost:3030/graphql"
// credentials: true
// credentials: "same-origin" // Additional fetch() options like `credentials` or `headers`
}),
cache: new InMemoryCache().restore(initialState)
});
}
function create(
initialState?: NormalizedCacheObject,
cookie?: string,
host?: string
) {
return new ApolloClient({
connectToDevTools: process.browser,
ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
link: new HttpLink({
uri: `${host || ""}/api/graphql`,
credentials: "include",
headers: cookie && {
Cookie: cookie
}
}),
cache: new InMemoryCache().restore(initialState || {})
});
}
function create(host: string, initialState: NormalizedCacheObject | null) {
const url =
process.env.NODE_ENV === "production"
? `https://${host}`
: "http://localhost:2999";
return new ApolloClient({
connectToDevTools: process.browser,
ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
link: new HttpLink({
uri: `${url}/api/graphql`,
credentials: "same-origin"
}),
cache: new InMemoryCache().restore(initialState || {})
});
}
function create(initialState) {
const httpLink = new HttpLink({
uri: process.env.API_URL
})
const cache = new InMemoryCache().restore(initialState || {})
const stateLink = withClientState({
resolvers,
defaults,
typeDefs,
cache
})
const authLink = setContext(async (req, prevCtx) => {
try {
let authHeaders = {}
if (process.browser) {
const create = (initialState: any) =>
new ApolloClient({
connectToDevTools: process.browser,
ssrMode: !process.browser,
link: new HttpLink({
uri: process.env.API_URL,
credentials: 'same-origin',
fetch
}),
cache: new InMemoryCache().restore(initialState || {})
})
function create(initialState, nowUrl) {
const url = process.env.api ? process.env.api : nowUrl;
return new ApolloClient({
connectToDevTools: process.browser,
ssrMode: !process.browser,
link: new HttpLink({
uri: `${url}/api/graphql`,
credentials: "same-origin"
}),
cache: new InMemoryCache().restore(initialState || {})
});
}