Skip to content

Commit 9f09e30

Browse files
wmertensThangHuuVu
andauthored
fix(qwik): don't build server deps on client (#12723)
The optimizer doesn't fully remove server imports and it helps to put `isServer` guards so server-side modules are not bundled for the client Co-authored-by: Thang Vu <[email protected]>
1 parent 4155eee commit 9f09e30

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

packages/frameworks-qwik/src/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@
110110
*/
111111

112112
import type { AuthConfig } from "@auth/core"
113-
import { Auth, isAuthAction, skipCSRFCheck, customFetch } from "@auth/core"
113+
import {
114+
Auth,
115+
isAuthAction,
116+
skipCSRFCheck,
117+
customFetch as _customFetch,
118+
} from "@auth/core"
114119
import { AuthAction, Session } from "@auth/core/types"
115120
import { implicit$FirstArg, type QRL } from "@builder.io/qwik"
116121
import {
@@ -124,7 +129,8 @@ import { EnvGetter } from "@builder.io/qwik-city/middleware/request-handler"
124129
import { isServer } from "@builder.io/qwik/build"
125130
import { parseString, splitCookiesString } from "set-cookie-parser"
126131

127-
export { customFetch }
132+
export const customFetch = isServer ? _customFetch : undefined
133+
128134
export { AuthError, CredentialsSignin } from "@auth/core/errors"
129135

130136
export type {
@@ -149,6 +155,7 @@ export function QwikAuthQrl(
149155
{ providerId, redirectTo: _redirectTo, options, authorizationParams },
150156
req
151157
) => {
158+
if (!isServer) return
152159
const { redirectTo = _redirectTo ?? defaultRedirectTo(req), ...rest } =
153160
options ?? {}
154161

@@ -192,6 +199,7 @@ export function QwikAuthQrl(
192199

193200
const useSignOut = globalAction$(
194201
async ({ redirectTo }, req) => {
202+
if (!isServer) return
195203
redirectTo ??= defaultRedirectTo(req)
196204
const authOpts = await authOptions(req)
197205
setEnvDefaults(req.env, authOpts)
@@ -261,6 +269,7 @@ async function authAction(
261269
path: string,
262270
authOptions: QwikAuthConfig
263271
) {
272+
if (!isServer) return
264273
const request = new Request(new URL(path, req.request.url), {
265274
method: req.request.method,
266275
headers: req.request.headers,
@@ -337,6 +346,7 @@ async function getSessionData(
337346
}
338347

339348
export const setEnvDefaults = (env: EnvGetter, config: AuthConfig) => {
349+
if (!isServer) return
340350
config.basePath = "/auth"
341351
if (!config.secret?.length) {
342352
config.secret = []

0 commit comments

Comments
 (0)