Pander
Pander
BABetter Auth
Created by Pander on 2/19/2025 in #bug-reports
Manually verifying magic link token throws unexpected invalid_type
In my Expo mobile app, I'm trying to verify the magic link token manually as described here. But when I try to call the verify method with my token, I receive the following error:
{"code": "______CODE_INVALID_TYPE____EXPECTED_STRING____RECEIVED_UNDEFINED____PATH_______TOKEN________MESSAGE_REQUIRED__", "details": [{"code": "invalid_type", "expected": "string", "message": "Required", "path": [Array], "received": "undefined"}], "message": "[
{
\"code\": \"invalid_type\",
\"expected\": \"string\",
\"received\": \"undefined\",
\"path\": [
\"token\"
],
\"message\": \"Required\"
}
]", "status": 400, "statusText": ""}
{"code": "______CODE_INVALID_TYPE____EXPECTED_STRING____RECEIVED_UNDEFINED____PATH_______TOKEN________MESSAGE_REQUIRED__", "details": [{"code": "invalid_type", "expected": "string", "message": "Required", "path": [Array], "received": "undefined"}], "message": "[
{
\"code\": \"invalid_type\",
\"expected\": \"string\",
\"received\": \"undefined\",
\"path\": [
\"token\"
],
\"message\": \"Required\"
}
]", "status": 400, "statusText": ""}
and this is my code setup:
import * as SecureStore from 'expo-secure-store'
import { createAuthClient } from 'better-auth/react'
import { expoClient } from '@better-auth/expo/client'
import { magicLinkClient } from 'better-auth/client/plugins'

export const auth = createAuthClient({
baseURL: process.env.EXPO_PUBLIC_API_URl,
plugins: [magicLinkClient(), expoClient({ storage: SecureStore })],
})

auth.magicLink.verify({ query: { token: 'inserted_valid_token' } }).then((res) => console.log(res.error))
import * as SecureStore from 'expo-secure-store'
import { createAuthClient } from 'better-auth/react'
import { expoClient } from '@better-auth/expo/client'
import { magicLinkClient } from 'better-auth/client/plugins'

export const auth = createAuthClient({
baseURL: process.env.EXPO_PUBLIC_API_URl,
plugins: [magicLinkClient(), expoClient({ storage: SecureStore })],
})

auth.magicLink.verify({ query: { token: 'inserted_valid_token' } }).then((res) => console.log(res.error))
I can verify that we're actually sending a token as string. Anyone has any idea perhaps? Thanks!
2 replies
BABetter Auth
Created by Pander on 2/19/2025 in #help
Retrieving session after magic link signin in Expo
Hi guys, We've set up Better Auth server in our nextjs app and created a successfull authentication setup. Now we're trying to use that same setup for our login on our Expo mobile app. For both the platforms we use a magic link. I've followed the setup here: https://www.better-auth.com/docs/integrations/expo with a custom server. I've managed to create a succesful login and deeplinking in the app based on the callback url looking something like this: http://localhost:3000/api/auth/magic-link/verify?token=super-secret-token-here&callbackURL=exp://192.168.1.60:8081/--/customer/(tabs)/home But when the app navigates to that screen and I call auth.useSession(), the session is always null. Does anyone have a clue on what I'm missing? "@better-auth/expo": "^1.1.18", "better-auth": "^1.1.18", ``` database: drizzleAdapter(db, { provider: 'pg', schema: { user: schema.user, session: schema.session, account: schema.account, verification: schema.verification, }, }), user: { additionalFields: { activeCompanyId: { required: false, type: 'string', }, type: { type: 'string', }, language: { type: 'string', }, dateFormat: { type: 'string', }, timeFormat: { type: 'string', }, }, }, plugins: [ expo(), magicLink({ disableSignUp: true, sendMagicLink, }), ], trustedOrigins: ['*'], // ['exp://'],
6 replies