Seeing several type errors / breaking changes after updating 1.2.5 -> 1.2.8

Running into some issues after upgrading better-auth: - fetchOptions is no longer accepted in auth.api calls - query now appears to be required for auth.api - authClient.useSession → now needs to be accessed via createAuthClient().useSession() - Can’t access methods like authClient.organization.cancelInvitation or inviteMember
await authClient.organization.cancelInvitation({
invitationId: invitation.id,
})
await authClient.organization.cancelInvitation({
invitationId: invitation.id,
})
Not sure what the recommended migration path is - is there an upgrade guide available? Also wondering if there are any plans to adopt semver for better-auth?
14 Replies
Ping
Ping4mo ago
fetchOptions is a authClient thing query being required depends on the endpoint's method, if the method is using GET then it's query, otherwise if it's POST then it's body authClient.useSession should still work. the authClient.organization.cancelInvitation still exists:
No description
kristen
kristenOP4mo ago
hmm I'm getting a type error with authClient.useSession where useSession returns "never" for data:
(property) useSession: () => {
data: never;
isPending: boolean;
error: BetterFetchError | null;
refetch: () => void;
}
(property) useSession: () => {
data: never;
isPending: boolean;
error: BetterFetchError | null;
refetch: () => void;
}
and I'm getting the following type error for cancelInvitation
Property 'cancelInvitation' does not exist on type '{ checkRolePermission: <R extends "owner" | "member" | "admin">(data: ({ permission: { readonly organization?: ("update" | "delete")[] | undefined; readonly member?: ("create" | "update" | "delete")[] | undefined; readonly invitation?: ("create" | "cancel")[] | undefined; readonly team?: ("create" | ... 1 more ... |...'.
Property 'cancelInvitation' does not exist on type '{ checkRolePermission: <R extends "owner" | "member" | "admin">(data: ({ permission: { readonly organization?: ("update" | "delete")[] | undefined; readonly member?: ("create" | "update" | "delete")[] | undefined; readonly invitation?: ("create" | "cancel")[] | undefined; readonly team?: ("create" | ... 1 more ... |...'.
Ping
Ping4mo ago
Can you show me your auth client config?
kristen
kristenOP4mo ago
yes - can I dm you?
Ping
Ping4mo ago
Sure.
kristen
kristenOP4mo ago
okay I ran into character limits, so just sending it as a txt file without the imports, let me know if that works
Ping
Ping4mo ago
I mean the auth client config, not the auth config.
kristen
kristenOP4mo ago
export const authClient = createAuthClient({
plugins: [organizationClient(), apiKeyClient(), workspaceClient()],
baseURL:
typeof window !== 'undefined'
? window.location.origin
: process.env.NEXT_PUBLIC_AUTH_BASE_URL || 'http://localhost:3000',
fetchOptions: {
onSuccess: (ctx) => {
const jwtToken = ctx.response.headers.get('set-auth-jwt')

if (jwtToken) {
safeStorage.setItem('jwt_token', jwtToken)
} else if (safeStorage.getItem('jwt_token')) {
safeStorage.removeItem('jwt_token')
}
},
auth: {
type: 'Bearer',
token: () => safeStorage.getItem('jwt_token') || '',
},
},
})
export const authClient = createAuthClient({
plugins: [organizationClient(), apiKeyClient(), workspaceClient()],
baseURL:
typeof window !== 'undefined'
? window.location.origin
: process.env.NEXT_PUBLIC_AUTH_BASE_URL || 'http://localhost:3000',
fetchOptions: {
onSuccess: (ctx) => {
const jwtToken = ctx.response.headers.get('set-auth-jwt')

if (jwtToken) {
safeStorage.setItem('jwt_token', jwtToken)
} else if (safeStorage.getItem('jwt_token')) {
safeStorage.removeItem('jwt_token')
}
},
auth: {
type: 'Bearer',
token: () => safeStorage.getItem('jwt_token') || '',
},
},
})
Ping
Ping4mo ago
@kristen If you removed all of the client plugins, does the types fix itself for the useSession data?
kristen
kristenOP4mo ago
ah, I created my own custom plugin (workspaceClient). when I removed it and all of its logic, then my app was able to build. Is there an upgrade path for a custom plugin?
Ping
Ping4mo ago
No, most cases you would get type errors if something changed
kristen
kristenOP4mo ago
hmm, have any ideas why it might be affecting the auth client's useSession type?
Ping
Ping4mo ago
Can i see your code?
kristen
kristenOP4mo ago

Did you find this page helpful?