Better AuthBA
Better Auth•12mo ago
Imam

Cors Error on Elysia with Node Adapter

i always got cors error only for better-auth api on Elysia, here is my backend code (Elysia):
import { cors } from '@elysiajs/cors';
import { node } from '@elysiajs/node';
import { swagger } from '@elysiajs/swagger';
import { db } from '@repo/db';
import { Elysia } from 'elysia';

import betterAuthView from './libs/auth';

// import { userMiddleware } from './middlewares/auth-middleware';

const app = new Elysia({ adapter: node() })
  .use(
    cors({
      origin: 'http://localhost:3000',
      credentials: true,
    })
  )
  .use(swagger())
  .onRequest(({ set }) => {
    set.headers['access-control-allow-credentials'] = 'true';
  })
  // .derive(userMiddleware)
  .all('/api/auth/*', betterAuthView)
  .get('/', async () => {
    return {
      message: 'Hello',
    };
  })
  .get('/api', async () => {
    return { message: 'Hello from API' };
  })
  .post('/api/users', async () => {
    const users = await db.query.userTable.findMany();

    return users;
  })

  .listen(process.env.PORT);

console.log(`🦊 Elysia is running at http://localhost:${process.env.PORT}`);

export type App = typeof app;

my github repo link: https://github.com/mamlzy/cms-hono.git (on
elysia
branch)
image.png
GitHub
Contribute to mamlzy/cms-hono development by creating an account on GitHub.
Was this page helpful?