pach
pach
TTCTheo's Typesafe Cult
Created by pach on 5/7/2023 in #questions
trpc useQuery adds "?" to the url every fetch, refreshing the page and resetting the state
I am using create-t3-app with all the included "addons"
// snippet from my pages/admin.tsx
const context = api.useContext();

const getUsersQuery = api.adminRouter.getUsers.useQuery();
const createUserMutation = api.adminRouter.createUser.useMutation();
const editUserMutation = api.adminRouter.editUser.useMutation();
const deleteUserMutation = api.adminRouter.deleteUser.useMutation();

const closeModal = () => {
setEditUser(false);
setShowNewAccountModal(false);
};

const createAccount: CreateAccount = async (email, flags) => {
if (editUser) {
await editUserMutation.mutateAsync({ email, flags });
} else {
await createUserMutation.mutateAsync({ email, flags });
}
closeModal();
await context.adminRouter.getUsers.invalidate();
};
// snippet from my pages/admin.tsx
const context = api.useContext();

const getUsersQuery = api.adminRouter.getUsers.useQuery();
const createUserMutation = api.adminRouter.createUser.useMutation();
const editUserMutation = api.adminRouter.editUser.useMutation();
const deleteUserMutation = api.adminRouter.deleteUser.useMutation();

const closeModal = () => {
setEditUser(false);
setShowNewAccountModal(false);
};

const createAccount: CreateAccount = async (email, flags) => {
if (editUser) {
await editUserMutation.mutateAsync({ email, flags });
} else {
await createUserMutation.mutateAsync({ email, flags });
}
closeModal();
await context.adminRouter.getUsers.invalidate();
};
what happens is when I fill in the form, and submit it, createAccount(email, flags) is called, it then loads and the page is refreshed the url changes from localhost:3000/admin to localhost:3000/admin? the only reason this is an issue is because of how im handling the panel with different "pages" and tabs with the navbar, stored in useState which is reset when the page refreshes making the user have to click the Accounts tab again anyone know what I am doing wrong?
9 replies
TTCTheo's Typesafe Cult
Created by pach on 5/4/2023 in #questions
"Unsafe assignment of `any` value
I am using latest create-t3-app with prisma, tailwind nextAuth and trpc
7 replies
TTCTheo's Typesafe Cult
Created by pach on 3/22/2023 in #questions
is it "ideal" to directly fetch /api/trpc/route.procedure in another server
im wanting to use my create-t3-app app as main source of data for a different server, and for this i need to access data from the trpc server on the the other server, is it a good idea to just fetch (for example) http://localhost:3000/api/trpc/route.exampleProcedure in this other server the procedure is public anyway so handling request authentication doesnt need to be done
5 replies
TTCTheo's Typesafe Cult
Created by pach on 3/12/2023 in #questions
Wanting to save some data every 30 days from an external game server on my t3 app server database.
So I have a function that gets the 'total accounts' from an external api, every 30 days I want to save that number to my prisma database (running on the create-t3-app server), what would be a smart way to save this data I am thinking I would need to check if its been 30 days since the last data save, if yes then insert a new value with the date If not then wait ? But I am not sure how to do this properly
9 replies
TTCTheo's Typesafe Cult
Created by pach on 3/10/2023 in #questions
Get a users id (snowflake) when signing in 0Auth
I am using the create-t3-app setup with nextAuth, prisma and tRPC After setting up the Discord env variables and making my login page, it seems that the id in the user field of the session data isn't my "actual" Discord ID It is clf2f3yvh0000v07off4kpi78 rather than 843312530528796697 I need access to this number because I want to only let certain ID's access the app. I plan on using this to check with Discord's API if the user has a certain role in a certain discord before allowing them on the site, but without access to this number I don't see how this would be possible I haven't made any changes to the server auth code yet, only UI stuff Does anyone have any advice?
4 replies