Installation problems

Hi, I'm trying to discover better-auth, so I start installing elysia, prisma and then better-auth, except that by following the doc, the "installation" part, from start to finish, I still can't understand how it works, the route localhost:3000/api/auth doesn't work and tells me NOT_FOUND
Solution:
I think it's normal that /api/auth is not found.. 😅 There is nothing there to do after all...
Jump to solution
19 Replies
Ping
Ping4d ago
Hey, did you read Elysia docs as well? Could provide additional info which may have been missed in installation page. https://www.better-auth.com/docs/integrations/elysia
Elysia Integration | Better Auth
Integrate Better Auth with Elysia.
ɴᴇʟᴇᴏᴋᴏ
did i need to do all this part?
Ping
Ping4d ago
You need to mount the handler.
ɴᴇʟᴇᴏᴋᴏ
import { Elysia, Context } from "elysia";
import {auth} from "./auth";



const betterAuthView = (context: Context) => {
const BETTER_AUTH_ACCEPT_METHODS = ["POST", "GET"]
// validate request method
if(BETTER_AUTH_ACCEPT_METHODS.includes(context.request.method)) {
return auth.handler(context.request);
} else {
context.error(405)
}
}


const app = new Elysia()

app.mount(auth.handler);

app.all("/api/auth/*", betterAuthView)
app.listen(3000);

console.log(
`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`
);
import { Elysia, Context } from "elysia";
import {auth} from "./auth";



const betterAuthView = (context: Context) => {
const BETTER_AUTH_ACCEPT_METHODS = ["POST", "GET"]
// validate request method
if(BETTER_AUTH_ACCEPT_METHODS.includes(context.request.method)) {
return auth.handler(context.request);
} else {
context.error(405)
}
}


const app = new Elysia()

app.mount(auth.handler);

app.all("/api/auth/*", betterAuthView)
app.listen(3000);

console.log(
`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`
);
Ping
Ping4d ago
try calling http://localhost:3000/api/auth/ok To see what the result is
Solution
Ping
Ping4d ago
I think it's normal that /api/auth is not found.. 😅 There is nothing there to do after all
ɴᴇʟᴇᴏᴋᴏ
ohw.. it works thx but what did the betterAuthView
Ping
Ping4d ago
What do you mean betterAuthView?
ɴᴇʟᴇᴏᴋᴏ
const betterAuthView = (context: Context) => {
const BETTER_AUTH_ACCEPT_METHODS = ["POST", "GET"]
// validate request method
if(BETTER_AUTH_ACCEPT_METHODS.includes(context.request.method)) {
return auth.handler(context.request);
} else {
context.error(405)
}
}
const betterAuthView = (context: Context) => {
const BETTER_AUTH_ACCEPT_METHODS = ["POST", "GET"]
// validate request method
if(BETTER_AUTH_ACCEPT_METHODS.includes(context.request.method)) {
return auth.handler(context.request);
} else {
context.error(405)
}
}
this part cause i got ok on this route http://localhost:3000/api/auth/ok but other route like http://localhost:3000/api/auth/test did nothing
Ping
Ping4d ago
ok is a built in path. test isn't. It's used to test.
ɴᴇʟᴇᴏᴋᴏ
ok, as how i know the route for use betterauth?
Ping
Ping4d ago
You can use the openAPI plugin, which will show you all of the available paths in your setup. Although in most cases you won't be needing to use those paths, as the BetterAuthClient should be handling all of that for you on the front-end.
ɴᴇʟᴇᴏᴋᴏ
i think i need to watch a video for know how to use it
ɴᴇʟᴇᴏᴋᴏ
why i don't have routes?
No description
ɴᴇʟᴇᴏᴋᴏ
ohw... ok i see on auth/auth/references with openAPI plugin, but i can't have these routes on swagger? @Ping
Ping
Ping4d ago
Not sure how swagger works, you'll have to figure that one out yourself - sorry
ɴᴇʟᴇᴏᴋᴏ
ok thx
Ping
Ping4d ago
May I mark this thread as solved? @ɴᴇʟᴇᴏᴋᴏ
ɴᴇʟᴇᴏᴋᴏ
yes thx

Did you find this page helpful?