Skip to content

Commit efa63c5

Browse files
authored
fix: declare types for UserInfo and SessionData (#17)
1 parent 4b52cdb commit efa63c5

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"./server": "./src/server/index.js"
3232
},
3333
"main": "src/index.js",
34-
"types": "./src/index.d.ts",
34+
"types": "./src/types/index.d.ts",
3535
"files": [
3636
"src"
3737
],

src/index.d.ts src/types/auth0-solid-start.d.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,26 @@ declare module '@zentered/auth0-solid-start/api/logout' {
1111
declare module '@zentered/auth0-solid-start/server' {
1212
import type { ServerFunctionEvent } from 'solid-start/server'
1313
import type { Session } from 'solid-start/session/sessions'
14-
14+
export type { SessionData } from 'solid-start/session/sessions'
1515
export function getSession(event: ServerFunctionEvent): Promise<Session>
1616
}
1717

1818
declare module '@zentered/auth0-solid-start' {
1919
import { Accessor, JSX } from 'solid-js'
20+
import { SessionData } from 'solid-start/session/sessions'
2021
import type { WebAuth } from 'auth0-js'
21-
export type { SessionData } from 'solid-start/session/sessions'
2222

23-
type Organization = { id: string }
23+
export type UserInfo = SessionData['userInfo']
2424

25-
export interface User {
26-
[name: string]: unknown
27-
}
25+
type Organization = { id: string }
2826

2927
type Auth0Context = {
3028
auth0Client: WebAuth
3129
isAuthenticated: () => boolean
3230
isInitialized: () => boolean
3331
organization: Accessor<Organization>
3432
setInvitation: (invitation: string, org: string, orgName: string) => void
35-
user: Accessor<User>
33+
user: Accessor<SessionData['userInfo']>
3634
userId: Accessor<string>
3735
idToken: Accessor<string>
3836
accessToken: Accessor<string>

src/types/index.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// <reference path="./auth0-solid-start.d.ts"/>
2+
/// <reference path="./solid-start.d.ts"/>

src/types/solid-start.d.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'solid-start/session/sessions'
2+
3+
declare module 'solid-start/session/sessions' {
4+
type UserInfo = {
5+
sub: string
6+
nickname: string
7+
name: string
8+
picture: string
9+
updated_at: string
10+
org_id: string
11+
}
12+
13+
/*
14+
Note: This is the most basic form of SessionData, but sufficient for most of the times. Ideally, we should have built a discriminated union.
15+
One type would set the refreshToken as required when the scope is set to offline_access, and another type would ignore that field.
16+
*/
17+
export interface SessionData {
18+
accessToken: string
19+
idToken: string
20+
refreshToken?: string
21+
scope: string
22+
tokenType?: string
23+
userInfo: UserInfo
24+
userId: string
25+
orgId: string
26+
permissions?: unknown
27+
}
28+
}

0 commit comments

Comments
 (0)