Skip to content

Commit

Permalink
feat: AuthShowcase only makes query when logged in (#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-ehrlich authored Nov 3, 2022
1 parent fde5b76 commit 5d20745
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-clocks-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": minor
---

only try to get secret message if there is a user
7 changes: 5 additions & 2 deletions cli/template/page-studs/index/with-auth-trpc-tw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ const Home: NextPage = () => {
export default Home;

const AuthShowcase: React.FC = () => {
const { data: secretMessage } = trpc.auth.getSecretMessage.useQuery();

const { data: sessionData } = useSession();

const { data: secretMessage } = trpc.auth.getSecretMessage.useQuery(
undefined, // no input
{ enabled: sessionData?.user !== undefined },
);

return (
<div className="flex flex-col items-center justify-center gap-2">
{sessionData && (
Expand Down
7 changes: 5 additions & 2 deletions cli/template/page-studs/index/with-auth-trpc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ const Home: NextPage = () => {
export default Home;

const AuthShowcase: React.FC = () => {
const { data: secretMessage } = trpc.auth.getSecretMessage.useQuery();

const { data: sessionData } = useSession();

const { data: secretMessage } = trpc.auth.getSecretMessage.useQuery(
undefined, // no input
{ enabled: sessionData?.user !== undefined },
);

return (
<div className={styles.authShowcase}>
{sessionData && <p>Logged in as {sessionData?.user?.name}</p>}
Expand Down

0 comments on commit 5d20745

Please sign in to comment.