-
-
Notifications
You must be signed in to change notification settings - Fork 797
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix pages to never render if
Page.authenticate=true
and logged out …
…(patch) (#2476)
- Loading branch information
Showing
4 changed files
with
89 additions
and
7 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
36 changes: 36 additions & 0 deletions
36
test/integration/auth/pages/page-dot-authenticate-logout.tsx
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,36 @@ | ||
import logout from "app/mutations/logout" | ||
import getAuthenticatedBasic from "app/queries/getAuthenticatedBasic" | ||
import {BlitzPage, useMutation, useQuery} from "blitz" | ||
import {Suspense} from "react" | ||
|
||
function Content() { | ||
const [result] = useQuery(getAuthenticatedBasic, undefined) | ||
const [logoutMutation] = useMutation(logout) | ||
return ( | ||
<div> | ||
<div id="content">{result}</div> | ||
<button | ||
id="logout" | ||
onClick={async () => { | ||
await logoutMutation() | ||
}} | ||
> | ||
logout | ||
</button> | ||
</div> | ||
) | ||
} | ||
|
||
const Page: BlitzPage = () => { | ||
return ( | ||
<div id="page"> | ||
<Suspense fallback={"Loading..."}> | ||
<Content /> | ||
</Suspense> | ||
</div> | ||
) | ||
} | ||
|
||
Page.authenticate = {redirectTo: "/login"} | ||
|
||
export default Page |
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,39 @@ | ||
import logout from "app/mutations/logout" | ||
import getAuthenticatedBasic from "app/queries/getAuthenticatedBasic" | ||
import {BlitzPage, useMutation, useQuery} from "blitz" | ||
import {Suspense} from "react" | ||
|
||
function Content() { | ||
const [result] = useQuery(getAuthenticatedBasic, undefined) | ||
const [logoutMutation] = useMutation(logout) | ||
return ( | ||
<div> | ||
<div id="content">{result}</div> | ||
<button | ||
id="logout" | ||
onClick={async () => { | ||
await logoutMutation() | ||
}} | ||
> | ||
logout | ||
</button> | ||
</div> | ||
) | ||
} | ||
|
||
const Page: BlitzPage = () => { | ||
if (typeof window !== "undefined") { | ||
throw new Error("This code should never run") | ||
} | ||
return ( | ||
<div id="page"> | ||
<Suspense fallback={"Loading..."}> | ||
<Content /> | ||
</Suspense> | ||
</div> | ||
) | ||
} | ||
|
||
Page.authenticate = true | ||
|
||
export default Page |
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