Infer Additional fields

Hello everyone, how can I infer additional fields in the authclient in Expo, I'm using a monorepo where the nextjs app has the auth server, I try to import inferAdditionalfields i get
iOS Bundling failed 60ms node_modules/expo-router/entry.js (1 module)
The package at "node_modules/jose/dist/node/esm/runtime/base64url.js" attempted to import the Node standard library module "node:buffer".
It failed because the native React runtime does not include the Node standard library.
iOS Bundling failed 60ms node_modules/expo-router/entry.js (1 module)
The package at "node_modules/jose/dist/node/esm/runtime/base64url.js" attempted to import the Node standard library module "node:buffer".
It failed because the native React runtime does not include the Node standard library.
12 Replies
Ping
Ping2w ago
Interesting, I'm not sure if I can be of much help, but I will go check the codebase on this. Are you certain it's coming from the inferAdditionalFields client plugin?
CapnCrunch
CapnCrunchOP2w ago
Thank you for the help!
import { inferAdditionalFields } from "better-auth/client/plugins";
import { inferAdditionalFields } from "better-auth/client/plugins";
Yep if I add the plugin to the plugins array, i get the error removing it solves it. I'll dig around aswell
Ping
Ping2w ago
It seems the error comes from the jose lib. But I can't find it anywhere from inferAdditionalFields. By the way, is this error occurring IN runtime? Or does it show you that before hand?
bekacru
bekacru2w ago
what version of better auth are you using no expo?
CapnCrunch
CapnCrunchOP2w ago
1.1.19
bekacru
bekacru2w ago
can you share the whole code snippet, where you're initating the authClient?
CapnCrunch
CapnCrunchOP2w ago
import * as SecureStore from "expo-secure-store";
import { expoClient } from "@better-auth/expo/client";
import { createAuthClient } from "better-auth/react";
import { inferAdditionalFields } from "better-auth/client/plugins";
import type { auth } from "@acme/auth";

export const authClient = createAuthClient({
baseURL: "http://localhost:3000",
plugins: [
expoClient({
scheme: "pp-app",
storagePrefix: "pp-app",
storage: SecureStore,
}),
inferAdditionalFields<typeof auth>(),
],
});
import * as SecureStore from "expo-secure-store";
import { expoClient } from "@better-auth/expo/client";
import { createAuthClient } from "better-auth/react";
import { inferAdditionalFields } from "better-auth/client/plugins";
import type { auth } from "@acme/auth";

export const authClient = createAuthClient({
baseURL: "http://localhost:3000",
plugins: [
expoClient({
scheme: "pp-app",
storagePrefix: "pp-app",
storage: SecureStore,
}),
inferAdditionalFields<typeof auth>(),
],
});
Also get this in the console
WARN Attempted to import the module "/Users/gabo/development/ppsolutions/monorepo/node_modules/@noble/ciphers/crypto.js" which is not listed in the "exports" of "/Users/gabo/development/ppsolutions/monorepo/node_modules/@noble/ciphers" under the requested subpath "./crypto.js". Falling back to file-based resolution. Consider updating the call site or asking the package maintainer(s) to expose this API.
WARN Attempted to import the module "/Users/gabo/development/ppsolutions/monorepo/node_modules/@noble/hashes/crypto.js" which is not listed in the "exports" of "/Users/gabo/development/ppsolutions/monorepo/node_modules/@noble/hashes" under the requested subpath "./crypto.js". Falling back to file-based resolution. Consider updating the call site or asking the package maintainer(s) to expose this API.
The package at "node_modules/jose/dist/node/esm/runtime/base64url.js" attempted to import the Node standard library module "node:buffer".
It failed because the native React runtime does not include the Node standard library.
WARN Attempted to import the module "/Users/gabo/development/ppsolutions/monorepo/node_modules/@noble/ciphers/crypto.js" which is not listed in the "exports" of "/Users/gabo/development/ppsolutions/monorepo/node_modules/@noble/ciphers" under the requested subpath "./crypto.js". Falling back to file-based resolution. Consider updating the call site or asking the package maintainer(s) to expose this API.
WARN Attempted to import the module "/Users/gabo/development/ppsolutions/monorepo/node_modules/@noble/hashes/crypto.js" which is not listed in the "exports" of "/Users/gabo/development/ppsolutions/monorepo/node_modules/@noble/hashes" under the requested subpath "./crypto.js". Falling back to file-based resolution. Consider updating the call site or asking the package maintainer(s) to expose this API.
The package at "node_modules/jose/dist/node/esm/runtime/base64url.js" attempted to import the Node standard library module "node:buffer".
It failed because the native React runtime does not include the Node standard library.
auth.ts on my nextjs folder
import { expo } from "@better-auth/expo";
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { nextCookies } from "better-auth/next-js";

import { db } from "@acme/db";

export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "mysql",
}),
trustedOrigins: ["exp://"],
emailAndPassword: {
enabled: true,
},
session: {
expiresIn: 60 * 60 * 24 * 7, // 7 days
updateAge: 60 * 60 * 24, // 1 day (every 1 day the session expiration is updated)
cookieCache: {
enabled: true,
maxAge: 60 * 60 * 24 * 7, // 7 days
},
},
user: {
additionalFields: {
phone: {
type: "string",
required: true,
},
role: {
type: "string",
required: true,
default: "client",
validate: (value: string) =>
["client", "admin", "member"].includes(value),
},
},
},
rateLimit: {
window: 60, // time window in seconds
max: 5, // max requests in the window
},
plugins: [
expo(),
nextCookies(), // make sure this is the last plugin in the array
],
});

export type Session = typeof auth.$Infer.Session;
import { expo } from "@better-auth/expo";
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { nextCookies } from "better-auth/next-js";

import { db } from "@acme/db";

export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "mysql",
}),
trustedOrigins: ["exp://"],
emailAndPassword: {
enabled: true,
},
session: {
expiresIn: 60 * 60 * 24 * 7, // 7 days
updateAge: 60 * 60 * 24, // 1 day (every 1 day the session expiration is updated)
cookieCache: {
enabled: true,
maxAge: 60 * 60 * 24 * 7, // 7 days
},
},
user: {
additionalFields: {
phone: {
type: "string",
required: true,
},
role: {
type: "string",
required: true,
default: "client",
validate: (value: string) =>
["client", "admin", "member"].includes(value),
},
},
},
rateLimit: {
window: 60, // time window in seconds
max: 5, // max requests in the window
},
plugins: [
expo(),
nextCookies(), // make sure this is the last plugin in the array
],
});

export type Session = typeof auth.$Infer.Session;
bekacru
bekacru2w ago
can you update to 1.1.20-beta.2
CapnCrunch
CapnCrunchOP2w ago
updated no errors from the terminal, but the app loads fine and after a second i get this on devtools
console.js:614 TypeError: Cannot read property 'subtle' of undefined, js engine: hermes Error Component Stack:
at ContextNavigator (ExpoRoot.js:73:36)
at ExpoRoot (ExpoRoot.js:47:76)
at App (<anonymous>)
at ErrorToastContainer (ErrorToastContainer.tsx:4:11)
at ErrorOverlay (<anonymous>)
at withDevTools(ErrorOverlay) (withDevTools.ios.tsx:27:25)
at RCTView (<anonymous>)
at View (View.js:32:34)
at CssInterop.View (api.js:32:48)
at RCTView (<anonymous>)
at View (View.js:32:34)
at CssInterop.View (api.js:32:48)
at AppContainer (AppContainer-dev.js:87:11)
at main(RootComponent) (getCachedComponentWithDebugName.js:26:42)
console.js:614 TypeError: Cannot read property 'subtle' of undefined, js engine: hermes Error Component Stack:
at ContextNavigator (ExpoRoot.js:73:36)
at ExpoRoot (ExpoRoot.js:47:76)
at App (<anonymous>)
at ErrorToastContainer (ErrorToastContainer.tsx:4:11)
at ErrorOverlay (<anonymous>)
at withDevTools(ErrorOverlay) (withDevTools.ios.tsx:27:25)
at RCTView (<anonymous>)
at View (View.js:32:34)
at CssInterop.View (api.js:32:48)
at RCTView (<anonymous>)
at View (View.js:32:34)
at CssInterop.View (api.js:32:48)
at AppContainer (AppContainer-dev.js:87:11)
at main(RootComponent) (getCachedComponentWithDebugName.js:26:42)
CapnCrunch
CapnCrunchOP2w ago
No description
bekacru
bekacru2w ago
alright i'm gonna take a deeper look. for now if you downgrade to 1.1.18 it should work fine.
CapnCrunch
CapnCrunchOP2w ago
Thank you for the help I'll try 1.1.18 in the meantime Beautiful 1.1.18 works

Did you find this page helpful?