ruhroh
ruhroh
TTCTheo's Typesafe Cult
Created by ruhroh on 5/21/2023 in #questions
Typescript error when trying to access more user properties in my JWT token
Hello! I am using Next Auth and I have it built so that users will also have a username, and in my auth file, my jwt callback looks like this:
jwt: ({ token, user }) => {
console.log("JWT CALLBACK");
console.log({ user });
if (user) {
token.id = user.id;
token.email = user.email;
token.name = user.name;
token.username = user.username;
}
console.log({ token });
return token;
},
jwt: ({ token, user }) => {
console.log("JWT CALLBACK");
console.log({ user });
if (user) {
token.id = user.id;
token.email = user.email;
token.name = user.name;
token.username = user.username;
}
console.log({ token });
return token;
},
Unfortunately, I am getting this TypeScript error: Property 'username' does not exist on type 'User | AdapterUser'. After looking into it, I found that the user type is defined in the node_modules folder, and this is what both User and AdapterUser looks like:
export interface AdapterUser extends User {
id: string
email: string
emailVerified: Date | null
username: string
}
// and
export interface DefaultUser {
id: string
name?: string | null
email?: string | null
image?: string | null
username?: string | null
}

export interface User extends DefaultUser {}
export interface AdapterUser extends User {
id: string
email: string
emailVerified: Date | null
username: string
}
// and
export interface DefaultUser {
id: string
name?: string | null
email?: string | null
image?: string | null
username?: string | null
}

export interface User extends DefaultUser {}
As you can see I've tried adding username to either or, and both, but I'm still getting the same error (after a ts server refresh too) and my app also will not build because of it. Any help would be appreciated. Thank you!
4 replies
TTCTheo's Typesafe Cult
Created by ruhroh on 11/13/2022 in #questions
How would you make requests to an Open API that follows traditional REST using t3 stack
Hello! I was wondering how I would go about fetching data from an open API that follows the traditional RESTful format using trpc. I would normally go about this with simple axios calls on the client, but I figured that might not be standard practice and wanted to get some insight on what would be the best way to make calls to an external api in the T3 stack.
25 replies
TTCTheo's Typesafe Cult
Created by ruhroh on 10/22/2022 in #questions
Property 'useMutation' does not exist
Hello, I'm very new to T3 and pretty new to coding in general. Going through my first tutorial on youtube to build a simple application and it seems like there has been some small changes made recently in how you set up simple CRUD and I can't seem to figure it . Problem is simply that whenever I try to use tRPC's useMutation method here, it simply gives me an error saying that it "does not exist on type '{ useContext():..." despite following the tutorial.
const Home: NextPage = () => {
const [snippetText, setSnippetText] = useState("");
const snippet = trpc.useMutation("snippet.saveSnippet");

const handleSaveSnippet = async () => {
const newSnippet = await snippet.mutateAsync({
text: snippetText,
})
console.table(newSnippet);
}
const Home: NextPage = () => {
const [snippetText, setSnippetText] = useState("");
const snippet = trpc.useMutation("snippet.saveSnippet");

const handleSaveSnippet = async () => {
const newSnippet = await snippet.mutateAsync({
text: snippetText,
})
console.table(newSnippet);
}
6 replies