clemwo
clemwo
TTCTheo's Typesafe Cult
Created by clemwo on 9/28/2023 in #questions
How to call mutate only once on page visit? (For Change Email Confirmation Links)
Ok, I think I caught the issue. I have a Layout which contains a sidebar that fetches and displays data. Apparently this causes my component to render twice. If I comment out the sidebar the issue disappears. Thanks for the help, I really appreciate that!
12 replies
TTCTheo's Typesafe Cult
Created by clemwo on 9/28/2023 in #questions
How to call mutate only once on page visit? (For Change Email Confirmation Links)
if I add a console.log(emailResetSent.current); directly above the mutate I still can see two mutations happening and false being printed twice
12 replies
TTCTheo's Typesafe Cult
Created by clemwo on 9/28/2023 in #questions
How to call mutate only once on page visit? (For Change Email Confirmation Links)
Doesn't work unfortunately. Here's my code:
const emailResetSent = useRef(false);

useEffect(() => {
if (query.token && resetEmail.isIdle && !emailResetSent.current) {
resetEmail.mutate({ id: query.token });
emailResetSent.current = true;
}
}, [query.token, resetEmail]);
const emailResetSent = useRef(false);

useEffect(() => {
if (query.token && resetEmail.isIdle && !emailResetSent.current) {
resetEmail.mutate({ id: query.token });
emailResetSent.current = true;
}
}, [query.token, resetEmail]);
12 replies
TTCTheo's Typesafe Cult
Created by clemwo on 7/6/2023 in #questions
How to implement redirect based on user role
Thanks for the link, I'll check it out
11 replies
TTCTheo's Typesafe Cult
Created by clemwo on 7/6/2023 in #questions
How to implement redirect based on user role
Do you have any resources on how I could implement that specifically? Or a good example? I already found out that I can have protected pages with nextAuth: https://next-auth.js.org/tutorials/securing-pages-and-api-routes Im not sure how to access the session object there to get the user role
11 replies
TTCTheo's Typesafe Cult
Created by clemwo on 5/9/2023 in #questions
How to create an object with a mutation. Getting React error `Invalid hook call`
I found the solution to the issue here: https://discord.com/channels/966627436387266600/1097508051747082260/1097509504486211644 My code now works like this:
import { type NextPage } from "next";
import Header from "~/components/Header/Header";
import { api } from "~/utils/api";

const Create: NextPage = () => {
const { mutate } = api.users.create.useMutation();

return (
<>
<Header header="Create" />
<p>Create new Users here!</p>
<button onClick={() => mutate()}>Click Me</button>
</>
);
};

export default Create;
import { type NextPage } from "next";
import Header from "~/components/Header/Header";
import { api } from "~/utils/api";

const Create: NextPage = () => {
const { mutate } = api.users.create.useMutation();

return (
<>
<Header header="Create" />
<p>Create new Users here!</p>
<button onClick={() => mutate()}>Click Me</button>
</>
);
};

export default Create;
3 replies
TTCTheo's Typesafe Cult
Created by Christian Lind on 1/29/2023 in #questions
Unsafe return of any typed value, using prisma upsert
Interesting, just had that same error and thought it was my fault since I'm pretty beginner. Restarting VSCode completely now worked fine for me tho
19 replies