b3nab
b3nab
BABetter Auth
Created by b3nab on 2/21/2025 in #help
better-auth.two_factor cookie not removed on signout?
thanks for taking your time to reply. 🙂 Yes, that's the behaviour. Actually my issue was that since the cookie wasn't removed, then the user never was really signing out and it was redirected back to my /verify-two-factor page. I solved the issue by manually expiring the cookie "better-auth.two_factor". And about this I have a related question: this two_factor token even if already used to exchange it for an access token can be reused during this 10 min time window? Is it good on security side or should it be invalidated after it is being used?
12 replies
BABetter Auth
Created by b3nab on 2/21/2025 in #help
better-auth.two_factor cookie not removed on signout?
Even if the two_factor cookie has a short duration it should be correctly expired at some point, on the verifyTotp if possible, like remove the two_factor cookie and set just the session_token. What do you think @Ping ?
12 replies
BABetter Auth
Created by b3nab on 2/21/2025 in #help
better-auth.two_factor cookie not removed on signout?
No description
12 replies
BABetter Auth
Created by b3nab on 2/21/2025 in #help
better-auth.two_factor cookie not removed on signout?
Even for the two_factor cookie is the same
12 replies
BABetter Auth
Created by b3nab on 2/21/2025 in #help
better-auth.two_factor cookie not removed on signout?
No description
12 replies
BABetter Auth
Created by b3nab on 2/21/2025 in #help
better-auth.two_factor cookie not removed on signout?
also another strange issue I found on the authClient, the response.data from veriftTotp is a Blob. I'll let you know also for this
12 replies
BABetter Auth
Created by b3nab on 2/21/2025 in #help
better-auth.two_factor cookie not removed on signout?
yes sure
12 replies
BABetter Auth
Created by dan—1106 on 2/19/2025 in #help
Set the correct Typescript type when using plugins
So update on this: I got rid of the TS error by adding nanostores: "0.11.3" to my package.json and import * as nanostores from "nanostores" into the file where my generateBetterAuthClient function is present and it worked. But then where I use betterAuthClient it was back to the original problem, so twoFactor was a missing key in betterAuthClient (so no correct type and auto inference not working). So I modify the array without explicitly telling the type and I add the types that TS was not able to find, like so:
import type * as nanostores from 'nanostores'
import type * as simplewebauthn from '@simplewebauthn/server'

function generateBetterAuthClient(pluginOptions: BetterAuthPluginOptions) {
// const clientPlugins: BetterAuthClientPlugin[] = [twoFactorClient()]
const clientPlugins = [] // <<< HERE! Not add a type to the const so now it should be all dynamic inferred by TS
clientPlugins.push(twoFactorClient())
if (pluginOptions.betterAuthPlugins?.passkey) {
clientPlugins.push(passkeyClient())
}
return createAuthClient<{
plugins: typeof clientPlugins
}>({ plugins: clientPlugins })
}
import type * as nanostores from 'nanostores'
import type * as simplewebauthn from '@simplewebauthn/server'

function generateBetterAuthClient(pluginOptions: BetterAuthPluginOptions) {
// const clientPlugins: BetterAuthClientPlugin[] = [twoFactorClient()]
const clientPlugins = [] // <<< HERE! Not add a type to the const so now it should be all dynamic inferred by TS
clientPlugins.push(twoFactorClient())
if (pluginOptions.betterAuthPlugins?.passkey) {
clientPlugins.push(passkeyClient())
}
return createAuthClient<{
plugins: typeof clientPlugins
}>({ plugins: clientPlugins })
}
Hope it will help others. 😄
39 replies
BABetter Auth
Created by dan—1106 on 2/19/2025 in #help
Set the correct Typescript type when using plugins
mmhm the problem here seems to be this: https://github.com/microsoft/TypeScript/pull/58176#issuecomment-2052698294 So this means that TS is not able to resolve the type of nanostores because my project doesn't have that dependency but it's only used internally by better-auth.
39 replies
BABetter Auth
Created by dan—1106 on 2/19/2025 in #help
Set the correct Typescript type when using plugins
At first I was looking to fix the TS error with a type like this:
type BetterAuthClientWithPlugins = ReturnType<
typeof createAuthClient<{
plugins: [
ReturnType<typeof twoFactorClient>,
ReturnType<typeof passkeyClient>?
]
}>
>
type BetterAuthClientWithPlugins = ReturnType<
typeof createAuthClient<{
plugins: [
ReturnType<typeof twoFactorClient>,
ReturnType<typeof passkeyClient>?
]
}>
>
It has a limit, meaning that I need to know all the plugins that can be added here. But since everyone can develop a custom plugin this may be a limitation of the above type.
39 replies
BABetter Auth
Created by dan—1106 on 2/19/2025 in #help
Set the correct Typescript type when using plugins
Basically I'm trying to develop a plugin for Payload CMS and of course it should be like a dynamic wrapper around betterAuth. Also frontend side it will load plugins dynamically based on the plugin configuration.
39 replies
BABetter Auth
Created by dan—1106 on 2/19/2025 in #help
Set the correct Typescript type when using plugins
yep sure:
{
"compilerOptions": {
"baseUrl": ".",
"lib": [
"DOM",
"DOM.Iterable",
"ES2022"
],
"rootDir": "./",
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"esModuleInterop": true,
"module": "NodeNext",
"moduleResolution": "nodenext",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"emitDeclarationOnly": true,
"target": "ES2022",
"composite": true,
"plugins": [
{
"name": "next"
}
],
},
"include": [
"./src/**/*.ts",
"./src/**/*.tsx",
"./dev/next-env.d.ts"
],
}
{
"compilerOptions": {
"baseUrl": ".",
"lib": [
"DOM",
"DOM.Iterable",
"ES2022"
],
"rootDir": "./",
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"esModuleInterop": true,
"module": "NodeNext",
"moduleResolution": "nodenext",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"emitDeclarationOnly": true,
"target": "ES2022",
"composite": true,
"plugins": [
{
"name": "next"
}
],
},
"include": [
"./src/**/*.ts",
"./src/**/*.tsx",
"./dev/next-env.d.ts"
],
}
39 replies
BABetter Auth
Created by dan—1106 on 2/19/2025 in #help
Set the correct Typescript type when using plugins
I have something like this:
function generateBetterAuthClient(pluginOptions: BetterAuthPluginOptions) {
const clientPlugins: BetterAuthClientPlugin[] = [twoFactorClient()]
if (pluginOptions.betterAuthPlugins?.passkey) {
clientPlugins.push(passkeyClient())
}
return createAuthClient({ plugins: clientPlugins })
}
function generateBetterAuthClient(pluginOptions: BetterAuthPluginOptions) {
const clientPlugins: BetterAuthClientPlugin[] = [twoFactorClient()]
if (pluginOptions.betterAuthPlugins?.passkey) {
clientPlugins.push(passkeyClient())
}
return createAuthClient({ plugins: clientPlugins })
}
But typescript show an error on generateBetterAuthClient saying: The inferred type of "generateBetterAuthClient" cannot be named without a reference to ".pnpm/[email protected]/node_modules/nanostores". This is likely not portable. A type annotation is necessary.
39 replies
BABetter Auth
Created by dan—1106 on 2/19/2025 in #help
Set the correct Typescript type when using plugins
Ehy hello 🙂 I have a kinda similar problem as your. But instead my config object I pass to betterAuth({ ...config }) is dynamic because I use a function to generate the betterAuth instance based on parameter of the function. What could be the possible solutions to set the correct typescript type?
39 replies