Back

[Solved] Magic URL endpoint returns `501 Not Implemented` when in node environment

  • 0
  • Self Hosted
  • Auth
Sam K
30 Mar, 2024, 00:32

Hi πŸ™‚

I am trying to create a magic url token from the server side in nuxt I am using the rest api since the node-appwrite doesn't support Cloudflare pages/workers. When I call the endpoint /account/tokens/magic-url but it returns "https://selfhosted-url/v1/account/tokens/magic-url": 501 Not Implemented

My selfhosted version is running the latest appwrite version 1.5.4

my code

TypeScript
import { type Models, type AppwriteException } from 'node-appwrite';
import { ofetch } from 'ofetch';

export default defineEventHandler(async (event) => {
  const config = useRuntimeConfig(event);
  const url = config.appwrite.endpoint;
  const projectId = config.appwrite.projectId;

  const { email } = await readBody<{ email: string }>(event);
  const appUrl = config.public.app.url;

  try {
    const session = await ofetch<Models.Token>(`/account/tokens/magic-url`, {
      baseURL: url,
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'X-Appwrite-Project': projectId
      },
      body: {
        email,
        url: appUrl
      }
    });

    return session;
  } catch (error: any) {
    console.log(error);
    throw createError<AppwriteException>(error);
  }
});

Thanks

TL;DR
Magic URL endpoint was returning `501 Not Implemented` due to missing token with proper permissions and the userId in the request body. The issue was resolved by passing the correct token with permissions and including the userId in the request body.
Sam K
30 Mar, 2024, 00:39

[Solved] Magic URL endpoint returns 501 Not Implemented when in node environment

Sam K
30 Mar, 2024, 00:40

I found my mistake, I did not pass the token with the permissions to create a session and the body is missing the userId

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more