-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: session persistence after refresh [27]
- Loading branch information
Showing
10 changed files
with
231 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
// @ts-nocheck | ||
import "@testing-library/jest-dom" | ||
import { render, screen } from "@testing-library/react" | ||
import { render, screen, waitFor } from "@testing-library/react" | ||
import Dashboard from "../../pages/dashboard" | ||
import useWeb3AuthStore from "../../store/web3-auth" | ||
|
||
jest.mock("../../store/web3-auth", () => jest.fn()) | ||
describe("Dashboard", () => { | ||
it("renders login message if not connected", () => { | ||
it("renders login message if not connected", async () => { | ||
useWeb3AuthStore.mockReturnValue({ | ||
// provider: null, | ||
isConnected: () => false, | ||
}) | ||
render(<Dashboard />) | ||
expect( | ||
screen.getByText("Please login to view this page"), | ||
).toBeInTheDocument() | ||
await waitFor(() => { | ||
expect( | ||
screen.getByText("Please login to view this page"), | ||
).toBeInTheDocument() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from "react" | ||
import useAuthHandlers from "../hooks/useAuthHandlers" | ||
import useOpenLoginSession from "../hooks/useOpenLoginSession" | ||
|
||
const LoginWrapper = ({ children }: { children: React.ReactNode }) => { | ||
const { handleLogin } = useAuthHandlers() | ||
const [hasLoginAttempt, setHasLoginAttempt] = React.useState(false) | ||
const hasSession = useOpenLoginSession() | ||
|
||
React.useEffect(() => { | ||
if (hasSession && !hasLoginAttempt) { | ||
handleLogin({}, false) | ||
setHasLoginAttempt(true) | ||
} | ||
}, [handleLogin, hasLoginAttempt, hasSession]) | ||
|
||
return <>{children}</> | ||
} | ||
|
||
export default LoginWrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.