[GH-ISSUE #357] Help regarding magic link #25555

Closed
opened 2026-04-17 15:49:36 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @anmol-fzr on GitHub (Oct 28, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/357

Hey Im using magic-link to signin user but im verifying user using client.magicLink.verify

const { data, error } = await authClient.magicLink.verify({
  query: {
    token,
  },
});

but the response data of this method gives me back only status as boolean, how do i get the current session for this particular user

auth.ts

import { betterAuth } from "better-auth";
import { magicLink } from "better-auth/plugins";
import { MongoClient } from "mongodb";
import { mongodbAdapter } from "better-auth/adapters/mongodb";
import { envs } from "../utils";
import { publishOnMailQueue } from "../helper";

const client = new MongoClient(envs.MONGO_URI);

const auth = betterAuth({
  database: mongodbAdapter(client.db(), { generateId: false }),
  trustedOrigins: [
    "http://localhost:5173",
    "http://localhost:5173/auth/login",
    "http://localhost:5173/",
  ],
  plugins: [
    magicLink({
      sendMagicLink: async (data: {
        email: string;
        token: string;
        url: string;
      }) => {
        publishOnMailQueue(data);
      },
    }),
  ],
});

export { auth };

auth-client.ts


import { createAuthClient } from "better-auth/react";
import { magicLinkClient } from "better-auth/client/plugins";

const authClient = createAuthClient({
  baseURL: "http://localhost:3000",
  plugins: [magicLinkClient()],
});

export { authClient };

Originally created by @anmol-fzr on GitHub (Oct 28, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/357 Hey Im using magic-link to signin user but im verifying user using `client.magicLink.verify` ```typescript const { data, error } = await authClient.magicLink.verify({ query: { token, }, }); ``` but the response data of this method gives me back only status as boolean, how do i get the current session for this particular user `auth.ts` ```typescript import { betterAuth } from "better-auth"; import { magicLink } from "better-auth/plugins"; import { MongoClient } from "mongodb"; import { mongodbAdapter } from "better-auth/adapters/mongodb"; import { envs } from "../utils"; import { publishOnMailQueue } from "../helper"; const client = new MongoClient(envs.MONGO_URI); const auth = betterAuth({ database: mongodbAdapter(client.db(), { generateId: false }), trustedOrigins: [ "http://localhost:5173", "http://localhost:5173/auth/login", "http://localhost:5173/", ], plugins: [ magicLink({ sendMagicLink: async (data: { email: string; token: string; url: string; }) => { publishOnMailQueue(data); }, }), ], }); export { auth }; ``` `auth-client.ts` ```typescript import { createAuthClient } from "better-auth/react"; import { magicLinkClient } from "better-auth/client/plugins"; const authClient = createAuthClient({ baseURL: "http://localhost:3000", plugins: [magicLinkClient()], }); export { authClient }; ```
GiteaMirror added the locked label 2026-04-17 15:49:36 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#25555