Effect CommunityEC
Effect Community•7mo ago•
6 replies
Semaelse

Implementing a callback endpoint for authentication in your `effect-wrapper` can be a bit tricky,...

Hello, I am trying to make an effect-wrapper for better-auth but am struggling to properly implement the callback endpoints. AFAIK, the auth callback is only available under betterAuth.handler

How would I create a (catchAll?) endpoint that implements these?

const AuthGroupLive = HttpApiBuilder.group(MultaApi, "Auth", (handlers) =>
  Effect.gen(function* () {
    const auth = yield* Auth;

    return handlers
      .handle("SignInSocial", ({ payload }) =>
        Effect.gen(function* () {
          yield* Effect.log("🔧 SignInSocial called with", payload);

          const result = yield* auth.use((client) =>
            client.api.signInSocial({
              body: payload,
            }),
          );

          if (result.url) {
            yield* Effect.log("🔧 Redirecting to URL:", result.url);
            return HttpServerResponse.redirect(result.url);
          }
        }),
      )
);


^ This is how I handle the main endpoint, but auth/callback endpoint is not exposed under the API
  auth.use((client) =>
            client.handler()
             ^ General http handler
          );
Was this page helpful?