Skip to content

Commit 1afb0a9

Browse files
authored
fix(qwik): re-export missing core types from @auth/qwik (#11898)
1 parent 96f49e0 commit 1afb0a9

File tree

6 files changed

+75
-2
lines changed

6 files changed

+75
-2
lines changed

apps/dev/qwik/src/routes/[email protected]

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
import { QwikAuth$ } from "@auth/qwik"
1+
import { DefaultSession, QwikAuth$ } from "@auth/qwik"
22
import GitHub from "@auth/qwik/providers/github"
33

4+
declare module "@auth/qwik" {
5+
interface Session {
6+
user: {
7+
roles: string[]
8+
} & DefaultSession["user"]
9+
}
10+
}
11+
412
export const { onRequest, useSession, useSignIn, useSignOut } = QwikAuth$(
513
() => ({
614
providers: [GitHub],

apps/examples/qwik/src/routes/[email protected]

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
import { QwikAuth$ } from "@auth/qwik";
1+
import { DefaultSession, QwikAuth$ } from "@auth/qwik";
22
import GitHub from "@auth/qwik/providers/github";
33

4+
declare module "@auth/qwik" {
5+
interface Session {
6+
user: {
7+
roles: string[];
8+
} & DefaultSession["user"];
9+
}
10+
}
11+
412
export const { onRequest, useSession, useSignIn, useSignOut } = QwikAuth$(
513
() => ({
614
providers: [GitHub],

docs/pages/getting-started/typescript.mdx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,49 @@ export const { auth, handlers } = NextAuth({
7777
```
7878

7979
</Code.Next>
80+
<Code.Qwik>
81+
82+
```ts filename="[email protected]"
83+
import { DefaultSession, QwikAuth$ } from "@auth/qwik"
84+
85+
declare module "@auth/qwik" {
86+
/**
87+
* Returned by the `useSession` hook and the `session` object in the sharedMap
88+
*/
89+
interface Session {
90+
user: {
91+
/** The user's postal address. */
92+
address: string
93+
/**
94+
* By default, TypeScript merges new interface properties and overwrites existing ones.
95+
* In this case, the default session user properties will be overwritten,
96+
* with the new ones defined above. To keep the default session user properties,
97+
* you need to add them back into the newly declared interface.
98+
*/
99+
} & DefaultSession["user"]
100+
}
101+
}
102+
103+
export const { onRequest, useSession, useSignIn, useSignOut } = QwikAuth$(
104+
() => ({
105+
callbacks: {
106+
session({ session, token, user }) {
107+
// `session.user.address` is now a valid property, and will be type-checked
108+
// in places like `useSession().user` or `sharedMap.get('session').user`
109+
return {
110+
...session,
111+
user: {
112+
...session.user,
113+
address: user.address,
114+
},
115+
}
116+
},
117+
},
118+
})
119+
)
120+
```
121+
122+
</Code.Qwik>
80123
<Code.Svelte>
81124

82125
```ts filename="auth.ts"

packages/frameworks-qwik/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
"types": "./index.d.ts",
2929
"import": "./index.qwik.js"
3030
},
31+
"./adapters": {
32+
"types": "./adapters.d.ts"
33+
},
3134
"./providers": {
3235
"types": "./providers/index.d.ts"
3336
},
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type * from "@auth/core/adapters"

packages/frameworks-qwik/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ import { EnvGetter } from "@builder.io/qwik-city/middleware/request-handler"
124124
import { isServer } from "@builder.io/qwik/build"
125125
import { parseString, splitCookiesString } from "set-cookie-parser"
126126

127+
export { AuthError, CredentialsSignin } from "@auth/core/errors"
128+
129+
export type {
130+
Account,
131+
DefaultSession,
132+
Profile,
133+
Session,
134+
User,
135+
} from "@auth/core/types"
136+
127137
/** Configure the {@link QwikAuth$} method. */
128138
export interface QwikAuthConfig extends Omit<AuthConfig, "raw"> {}
129139

0 commit comments

Comments
 (0)