feat: export oAuthState for config use

This commit is contained in:
Dylan Vanmali
2026-02-07 10:02:40 -08:00
parent 4163102121
commit 6afa9f7041
3 changed files with 7 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ import { getSessionFromCtx } from "better-auth/api";
import { generateRandomString, makeSignature } from "better-auth/crypto";
import type { Verification } from "better-auth/db";
import { APIError } from "better-call";
import { oAuthState } from "./oauth";
import type {
OAuthAuthorizationQuery,
OAuthConsent,
@@ -131,6 +132,10 @@ export async function authorizeEndpoint(
// Check request
const query: OAuthAuthorizationQuery = ctx.query;
await oAuthState.set({
query: query.toString(),
});
if (!query.client_id) {
throw ctx.redirect(
getErrorURL(ctx, "invalid_client", "client_id is required"),

View File

@@ -5,5 +5,5 @@ export {
oauthProviderOpenIdConfigMetadata,
oidcServerMetadata,
} from "./metadata";
export { oauthProvider } from "./oauth";
export { getOAuthProviderState, oauthProvider } from "./oauth";
export type * from "./types";

View File

@@ -41,6 +41,7 @@ declare module "@better-auth/core" {
export const oAuthState = defineRequestState<{ query?: string } | null>(
() => null,
);
export const getOAuthProviderState = oAuthState.get;
/**
* oAuth 2.1 provider plugin for Better Auth.