Skip to content

Commit 880e7c7

Browse files
authored
fix: storeStateStrategy default to database if provided (#6619)
1 parent 24f486e commit 880e7c7

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

packages/better-auth/src/context/create-context.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ export async function createAuthContext(
170170
socialProviders: providers,
171171
options,
172172
oauthConfig: {
173-
storeStateStrategy: options.account?.storeStateStrategy || "database",
173+
storeStateStrategy:
174+
options.account?.storeStateStrategy ||
175+
(options.database ? "database" : "cookie"),
174176
skipStateCookieCheck: !!options.account?.skipStateCookieCheck,
175177
},
176178
tables,

packages/better-auth/src/oauth2/state.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ export async function generateState(
2727

2828
const codeVerifier = generateRandomString(128);
2929
const state = generateRandomString(32);
30-
const storeStateStrategy =
31-
c.context.oauthConfig?.storeStateStrategy || "cookie";
30+
const storeStateStrategy = c.context.oauthConfig.storeStateStrategy;
3231

3332
const stateData = {
3433
...(additionalData ? additionalData : {}),
@@ -99,8 +98,7 @@ export async function generateState(
9998

10099
export async function parseState(c: GenericEndpointContext) {
101100
const state = c.query.state || c.body.state;
102-
const storeStateStrategy =
103-
c.context.oauthConfig.storeStateStrategy || "cookie";
101+
const storeStateStrategy = c.context.oauthConfig.storeStateStrategy;
104102

105103
const stateDataSchema = z.looseObject({
106104
callbackURL: z.string(),

0 commit comments

Comments
 (0)