Skip to content

Commit 8a4da93

Browse files
committed
fix(qwik): don't build server deps on client
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
1 parent af2ccea commit 8a4da93

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/frameworks-qwik/src/index.ts

+11-2
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)
@@ -337,6 +345,7 @@ async function getSessionData(
337345
}
338346

339347
export const setEnvDefaults = (env: EnvGetter, config: AuthConfig) => {
348+
if (!isServer) return
340349
config.basePath = "/auth"
341350
if (!config.secret?.length) {
342351
config.secret = []

0 commit comments

Comments
 (0)