Skip to content

Commit

Permalink
Merge pull request #121 from EveripediaNetwork/fix-update-api-back-to…
Browse files Browse the repository at this point in the history
…-passing-cookie-to-provider

update api back to passing cookie to provider
  • Loading branch information
Royal-lobster authored Jan 2, 2025
2 parents 8c672c5 + 9e04ae7 commit 996c95c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-buttons-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@everipedia/iq-login": patch
---

update api back to passing cookie to provider
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,21 @@ export default config;
// app/layout.tsx

import { IqLoginProvider } from "@everipedia/iq-login/client";
import { getWagmiConfig } from "@everipedia/iq-login";
import { headers } from "next/headers";
import { cookieToInitialState } from "wagmi";

export default async function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
const initialStates = cookieToInitialState(
getWagmiConfig(),
(await headers()).get("cookie")
);
const cookie = (await headers()).get("cookie")

return (
<html lang="en">
<body>
<IqLoginProvider
projectName="YOUR_PROJECT_NAME" // Required: Project name for storage
initialStates={initialStates}
cookie={cookie}
>
{children}
</IqLoginProvider>
Expand Down
8 changes: 5 additions & 3 deletions src/components/iq-login-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { structuralSharing } from "@wagmi/core/query";
import type React from "react";
import { createContext, useState } from "react";
import { type State, WagmiProvider } from "wagmi";
import { cookieToInitialState, type State, WagmiProvider } from "wagmi";
import {
getWagmiConfig,
web3AuthInstance,
Expand All @@ -14,14 +14,14 @@ import { Web3AuthProvider } from "./web3-auth-provider";
interface IqLoginProviderProps {
children: React.ReactNode;
projectName: string;
initialState?: State;
cookie?: string | null;
}

export const ProjectContext = createContext<string>("");

export function IqLoginProvider({
children,
initialState,
cookie,
projectName,
}: IqLoginProviderProps) {
const [wagmiConfig] = useState(() => getWagmiConfig());
Expand All @@ -37,6 +37,8 @@ export function IqLoginProvider({
}),
);

const initialState = cookieToInitialState(wagmiConfig, cookie);

return (
<ProjectContext.Provider value={projectName}>
<WagmiProvider config={wagmiConfig} initialState={initialState}>
Expand Down

0 comments on commit 996c95c

Please sign in to comment.