blitz
blitz copied to clipboard
Adding new properties to session publicData causes type error in blitz-server.ts
What is the problem?
Adding new properties seems to be causing type error or changing the type of userId to string (uuid)
Paste all your error logs here:
Argument of type 'PrismaClient<PrismaClientOptions, unknown, unknown> & EnhancedPrismaClientAddedMethods' is not assignable to parameter of type 'PrismaClientWithSession'.
The types of 'session.update' are incompatible between these types.
Type '<T extends SessionUpdateArgs>(args: SelectSubset<T, SessionUpdateArgs>) => CheckSelect<T, Prisma__SessionClient<Session>, Prisma__SessionClient<...>>' is not assignable to type '(args: { data: Partial<SessionModel>; where: { handle?: string | undefined; }; }) => Promise<SessionModel>'.
Types of parameters 'args' and 'args' are incompatible.
Type '{ data: Partial<SessionModel>; where: { handle?: string | undefined; }; }' is not assignable to type '{ select?: SessionSelect | null | undefined; include?: SessionInclude | null | undefined; data: (Without<SessionUpdateInput, SessionUncheckedUpdateInput> & SessionUncheckedUpdateInput) | (Without<...> & SessionUpdateInput); where: SessionWhereUniqueInput; }'.
Types of property 'data' are incompatible.
Type 'Partial<SessionModel>' is not assignable to type '(Without<SessionUpdateInput, SessionUncheckedUpdateInput> & SessionUncheckedUpdateInput) | (Without<...> & SessionUpdateInput)'.
Type 'Partial<SessionModel>' is not assignable to type 'Without<SessionUncheckedUpdateInput, SessionUpdateInput> & SessionUpdateInput'.
Type 'Partial<SessionModel>' is not assignable to type 'Without<SessionUncheckedUpdateInput, SessionUpdateInput>'.
Types of property 'userId' are incompatible.
Type 'string | null | undefined' is not assignable to type 'undefined'.
Type 'null' is not assignable to type 'undefined'.
Paste all relevant code snippets here:
import {SimpleRolesIsAuthorized} from '@blitzjs/auth'
import {GlobalRole, MembershipRole} from 'db'
export type Role = MembershipRole | GlobalRole
declare module "@blitzjs/auth" {
export interface Session {
isAuthorized: SimpleRolesIsAuthorized<Role>
PublicData: {
userId: string
isAdmin: boolean
role?: GlobalRole
orgRole?: MembershipRole
orgId?: string
}
}
}
What are detailed steps to reproduce this?
- i believe this happens when adding properties to the session data.
- i could reproduce this twice but reverting it to original doesnt seem to fix it so i am not certain.
Run blitz -v
and paste the output here:
Blitz version: 2.0.0-beta.4 (global)
Blitz version: 2.0.0-beta.4 (local)
Windows 11 | win32-x64 | Node: v16.15.1
Package manager: npm
System:
OS: Windows 10 10.0.22000
CPU: (16) x64 AMD Ryzen 7 2700X Eight-Core Processor
Memory: 23.18 GB / 31.93 GB
Binaries:
Node: 16.15.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.18 - ~\.yarn\bin\yarn.CMD
npm: 8.11.0 - C:\Program Files\nodejs\npm.CMD
npmPackages:
@blitzjs/auth: 2.0.0-beta.4 => 2.0.0-beta.4
@blitzjs/next: 2.0.0-beta.4 => 2.0.0-beta.4
@blitzjs/rpc: 2.0.0-beta.4 => 2.0.0-beta.4
@prisma/client: 4.0.0 => 4.0.0
blitz: 2.0.0-beta.4 => 2.0.0-beta.4
next: 12.2.5 => 12.2.5
prisma: 4.0.0 => 4.0.0
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
typescript: ^4.5.3 => 4.8.3
Please include below any other applicable logs and screenshots that show your problem:
No response
Hey, I just created a new app, and changed my types.ts
file to be the same as yours. I also changed the Prisma schema to use uuid and String for userId
. I needed to get rid of a few as number
in changePassword, login, signup mutations and in getCurrentUser query. It works fine though — I didn't get any type issues. I made a minimal repro here: https://github.com/beerose/blitz-publicdata-repro/commit/73a3cf9318f920941c2801f6bb8144e3b8e29b93
Hello everyone. I am also having this issue but was able to resolve the type error that was coming up in my IDE.
However, I am still having this issue when I try to blitz build
Any help is appreciated and can be compensated. I have tried deleting node modules and the next cache. I updated to the latest version of blitz 2.0.0-beta.26 but I think this issue existed before and also happens in 25.
declare module "@blitzjs/auth" {
export interface Session {
isAuthorized: SimpleRolesIsAuthorized<Role>
PublicData: {
userId: string
username: string
// userId: User["id"]
// username: User["username"]
role: Role
}
}
}
I have been able to fix this issue by putting this into my tsconfig.json file
However, now everyplace where I have added username is giving me an error. It's a huge pain just to make the smallest db updates. Something isn't wrong and I don't know enough about typescript and prisma to manually fix an error that's autogenerated.
"strictNullChecks": true,