@absolutejs/auth 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +9 -0
- package/README.md +3 -3
- package/dist/index.js +2026 -1
- package/dist/src/authorize.d.ts +34 -3
- package/dist/src/callback.d.ts +4 -4
- package/dist/src/index.d.ts +77 -32
- package/dist/src/profile.d.ts +47 -0
- package/dist/src/protectRoute.d.ts +1 -1
- package/dist/src/refresh.d.ts +11 -8
- package/dist/src/revoke.d.ts +19 -18
- package/dist/src/{logout.d.ts → signout.d.ts} +7 -5
- package/dist/src/status.d.ts +4 -2
- package/dist/src/typeGuards.d.ts +0 -10
- package/dist/src/types.d.ts +37 -27
- package/dist/src/utils.d.ts +1 -1
- package/drizzle.config.ts +12 -0
- package/eslint.config.mjs +245 -0
- package/package.json +23 -6
- package/dist/src/profiles.d.ts +0 -10
- package/dist/src/providers.d.ts +0 -51
- package/src/authorize.ts +0 -119
- package/src/callback.ts +0 -132
- package/src/constants.ts +0 -13
- package/src/index.ts +0 -88
- package/src/logout.ts +0 -39
- package/src/profiles.ts +0 -322
- package/src/protectRoute.ts +0 -33
- package/src/providers.ts +0 -109
- package/src/refresh.ts +0 -63
- package/src/revoke.ts +0 -61
- package/src/sessionStore.ts +0 -10
- package/src/status.ts +0 -100
- package/src/typeGuards.ts +0 -32
- package/src/types.ts +0 -89
- package/src/utils.ts +0 -35
- package/tsconfig.json +0 -17
package/dist/src/authorize.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Elysia } from 'elysia';
|
|
2
|
-
import { ClientProviders } from './types';
|
|
2
|
+
import { AuthorizeRoute, ClientProviders } from './types';
|
|
3
3
|
type AuthorizeProps = {
|
|
4
4
|
clientProviders: ClientProviders;
|
|
5
|
-
authorizeRoute?:
|
|
5
|
+
authorizeRoute?: AuthorizeRoute;
|
|
6
6
|
onAuthorize?: () => void;
|
|
7
7
|
};
|
|
8
8
|
export declare const authorize: ({ clientProviders, authorizeRoute, onAuthorize }: AuthorizeProps) => Elysia<"", {
|
|
@@ -30,7 +30,8 @@ export declare const authorize: ({ clientProviders, authorizeRoute, onAuthorize
|
|
|
30
30
|
headers: unknown;
|
|
31
31
|
response: {
|
|
32
32
|
200: import("undici-types").Response;
|
|
33
|
-
400: "Provider is required" | "Invalid provider";
|
|
33
|
+
400: "Cookies are missing" | "Provider is required" | "Invalid provider";
|
|
34
|
+
401: "Invalid provider";
|
|
34
35
|
500: `${string} - ${string}` | `Unknown error: ${string}`;
|
|
35
36
|
422: {
|
|
36
37
|
type: "validation";
|
|
@@ -45,6 +46,36 @@ export declare const authorize: ({ clientProviders, authorizeRoute, onAuthorize
|
|
|
45
46
|
};
|
|
46
47
|
};
|
|
47
48
|
};
|
|
49
|
+
} | {
|
|
50
|
+
[x: string]: {
|
|
51
|
+
":provider": {
|
|
52
|
+
[x: string]: {
|
|
53
|
+
get: {
|
|
54
|
+
body: unknown;
|
|
55
|
+
params: {
|
|
56
|
+
provider: string;
|
|
57
|
+
};
|
|
58
|
+
query: unknown;
|
|
59
|
+
headers: unknown;
|
|
60
|
+
response: {
|
|
61
|
+
200: import("undici-types").Response;
|
|
62
|
+
400: "Cookies are missing" | "Provider is required" | "Invalid provider";
|
|
63
|
+
401: "Invalid provider";
|
|
64
|
+
500: `${string} - ${string}` | `Unknown error: ${string}`;
|
|
65
|
+
422: {
|
|
66
|
+
type: "validation";
|
|
67
|
+
on: string;
|
|
68
|
+
summary?: string;
|
|
69
|
+
message?: string;
|
|
70
|
+
found?: unknown;
|
|
71
|
+
property?: string;
|
|
72
|
+
expected?: string;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
};
|
|
48
79
|
}, {
|
|
49
80
|
derive: {};
|
|
50
81
|
resolve: {};
|
package/dist/src/callback.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Elysia } from 'elysia';
|
|
2
|
-
import { ClientProviders, OnCallback } from './types';
|
|
2
|
+
import { ClientProviders, OnCallback, RouteString } from './types';
|
|
3
3
|
type CallbackProps<UserType> = {
|
|
4
4
|
clientProviders: ClientProviders;
|
|
5
|
-
callbackRoute?:
|
|
5
|
+
callbackRoute?: RouteString;
|
|
6
6
|
onCallback?: OnCallback<UserType>;
|
|
7
7
|
};
|
|
8
8
|
export declare const callback: <UserType>({ clientProviders, callbackRoute, onCallback }: CallbackProps<UserType>) => Elysia<"", {
|
|
@@ -29,9 +29,9 @@ export declare const callback: <UserType>({ clientProviders, callbackRoute, onCa
|
|
|
29
29
|
headers: unknown;
|
|
30
30
|
response: {
|
|
31
31
|
200: import("undici-types").Response;
|
|
32
|
-
|
|
33
|
-
400: "Invalid callback request" | "Invalid state mismatch" | "Code verifier not found and is required";
|
|
32
|
+
400: "Cookies are missing" | "Invalid callback request" | "Invalid state mismatch" | "Code verifier not found and is required";
|
|
34
33
|
401: "Invalid provider" | "No auth provider found";
|
|
34
|
+
500: `${string} - ${string}` | `Failed to validate authorization code: Unknown error: ${string}`;
|
|
35
35
|
};
|
|
36
36
|
};
|
|
37
37
|
};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
import { OAuth2RequestError, ArcticFetchError } from 'arctic';
|
|
2
1
|
import { Elysia } from 'elysia';
|
|
3
2
|
import { AbsoluteAuthProps } from './types';
|
|
4
|
-
export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callbackRoute,
|
|
3
|
+
export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callbackRoute, profileRoute, signoutRoute, statusRoute, refreshRoute, revokeRoute, onAuthorize, onProfile, onCallback, onStatus, onRefresh, onSignOut, onRevocation }: AbsoluteAuthProps<UserType>) => Elysia<"", {
|
|
5
4
|
decorator: {};
|
|
6
5
|
store: {
|
|
7
|
-
session: import("./types").SessionRecord<
|
|
6
|
+
session: import("./types").SessionRecord<unknown> & import("./types").SessionRecord<UserType>;
|
|
8
7
|
};
|
|
9
8
|
derive: {};
|
|
10
9
|
resolve: {};
|
|
11
10
|
}, {
|
|
12
|
-
error: {
|
|
13
|
-
OAUTH2_REQUEST_ERROR: OAuth2RequestError;
|
|
14
|
-
ARCTIC_FETCH_ERROR: ArcticFetchError;
|
|
15
|
-
};
|
|
11
|
+
error: {};
|
|
16
12
|
typebox: import("@sinclair/typebox").TModule<{}, {}>;
|
|
17
13
|
}, {
|
|
18
14
|
schema: {};
|
|
19
15
|
macro: {};
|
|
20
16
|
macroFn: {};
|
|
21
17
|
parser: {};
|
|
22
|
-
}, {
|
|
18
|
+
}, ((({
|
|
23
19
|
[x: string]: {
|
|
24
20
|
post: {
|
|
25
21
|
body: unknown;
|
|
@@ -28,29 +24,29 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
|
|
|
28
24
|
headers: unknown;
|
|
29
25
|
response: {
|
|
30
26
|
200: Response;
|
|
27
|
+
400: "Cookies are missing";
|
|
31
28
|
401: "No auth provider found";
|
|
32
|
-
500: `Failed to
|
|
29
|
+
500: `Failed to signout: ${string}`;
|
|
33
30
|
};
|
|
34
31
|
};
|
|
35
32
|
};
|
|
36
33
|
} & {
|
|
37
34
|
[x: string]: {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
};
|
|
35
|
+
post: {
|
|
36
|
+
body: unknown;
|
|
37
|
+
params: {};
|
|
38
|
+
query: unknown;
|
|
39
|
+
headers: unknown;
|
|
40
|
+
response: {
|
|
41
|
+
200: Response;
|
|
42
|
+
400: "Cookies are missing" | "Invalid provider";
|
|
43
|
+
401: "Invalid provider" | "No auth provider found" | "No user session found";
|
|
44
|
+
501: "Provider does not support revocation";
|
|
45
|
+
500: `Failed to revoke token: ${string}`;
|
|
50
46
|
};
|
|
51
47
|
};
|
|
52
48
|
};
|
|
53
|
-
} & {
|
|
49
|
+
} & ({
|
|
54
50
|
[x: string]: {
|
|
55
51
|
get: {
|
|
56
52
|
body: unknown;
|
|
@@ -59,12 +55,14 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
|
|
|
59
55
|
headers: unknown;
|
|
60
56
|
response: {
|
|
61
57
|
200: Response;
|
|
58
|
+
400: "Cookies are missing";
|
|
59
|
+
401: "Invalid provider";
|
|
62
60
|
501: "Provider is not refreshable";
|
|
63
61
|
500: `Error: ${string} - ${string}` | `Unknown Error: ${string}`;
|
|
64
62
|
};
|
|
65
63
|
};
|
|
66
64
|
};
|
|
67
|
-
} & {
|
|
65
|
+
} & ({
|
|
68
66
|
[x: string]: {
|
|
69
67
|
post: {
|
|
70
68
|
body: unknown;
|
|
@@ -73,13 +71,14 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
|
|
|
73
71
|
headers: unknown;
|
|
74
72
|
response: {
|
|
75
73
|
200: Response;
|
|
76
|
-
|
|
74
|
+
400: "Cookies are missing" | "Invalid provider" | "No refresh token found";
|
|
75
|
+
401: "Invalid provider" | "No auth provider found" | "No user session found";
|
|
77
76
|
501: "Provider is not refreshable";
|
|
78
|
-
500: `Failed to refresh token: ${string}
|
|
77
|
+
500: `Failed to refresh token: ${string}`;
|
|
79
78
|
};
|
|
80
79
|
};
|
|
81
80
|
};
|
|
82
|
-
} & {
|
|
81
|
+
} & ({
|
|
83
82
|
[x: string]: {
|
|
84
83
|
":provider": {
|
|
85
84
|
get: {
|
|
@@ -91,7 +90,8 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
|
|
|
91
90
|
headers: unknown;
|
|
92
91
|
response: {
|
|
93
92
|
200: import("undici-types").Response;
|
|
94
|
-
400: "Provider is required" | "Invalid provider";
|
|
93
|
+
400: "Cookies are missing" | "Provider is required" | "Invalid provider";
|
|
94
|
+
401: "Invalid provider";
|
|
95
95
|
500: `${string} - ${string}` | `Unknown error: ${string}`;
|
|
96
96
|
422: {
|
|
97
97
|
type: "validation";
|
|
@@ -106,7 +106,37 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
|
|
|
106
106
|
};
|
|
107
107
|
};
|
|
108
108
|
};
|
|
109
|
-
}
|
|
109
|
+
} | {
|
|
110
|
+
[x: string]: {
|
|
111
|
+
":provider": {
|
|
112
|
+
[x: string]: {
|
|
113
|
+
get: {
|
|
114
|
+
body: unknown;
|
|
115
|
+
params: {
|
|
116
|
+
provider: string;
|
|
117
|
+
};
|
|
118
|
+
query: unknown;
|
|
119
|
+
headers: unknown;
|
|
120
|
+
response: {
|
|
121
|
+
200: import("undici-types").Response;
|
|
122
|
+
400: "Cookies are missing" | "Provider is required" | "Invalid provider";
|
|
123
|
+
401: "Invalid provider";
|
|
124
|
+
500: `${string} - ${string}` | `Unknown error: ${string}`;
|
|
125
|
+
422: {
|
|
126
|
+
type: "validation";
|
|
127
|
+
on: string;
|
|
128
|
+
summary?: string;
|
|
129
|
+
message?: string;
|
|
130
|
+
found?: unknown;
|
|
131
|
+
property?: string;
|
|
132
|
+
expected?: string;
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
})))) & {
|
|
110
140
|
[x: string]: {
|
|
111
141
|
get: {
|
|
112
142
|
body: unknown;
|
|
@@ -115,15 +145,30 @@ export declare const absoluteAuth: <UserType>({ config, authorizeRoute, callback
|
|
|
115
145
|
headers: unknown;
|
|
116
146
|
response: {
|
|
117
147
|
200: import("undici-types").Response;
|
|
118
|
-
|
|
119
|
-
400: "Invalid callback request" | "Invalid state mismatch" | "Code verifier not found and is required";
|
|
148
|
+
400: "Cookies are missing" | "Invalid callback request" | "Invalid state mismatch" | "Code verifier not found and is required";
|
|
120
149
|
401: "Invalid provider" | "No auth provider found";
|
|
150
|
+
500: `${string} - ${string}` | `Failed to validate authorization code: Unknown error: ${string}`;
|
|
121
151
|
};
|
|
122
152
|
};
|
|
123
153
|
};
|
|
124
|
-
}
|
|
154
|
+
}) & {
|
|
155
|
+
[x: string]: {
|
|
156
|
+
get: {
|
|
157
|
+
body: unknown;
|
|
158
|
+
params: {};
|
|
159
|
+
query: unknown;
|
|
160
|
+
headers: unknown;
|
|
161
|
+
response: {
|
|
162
|
+
200: Response;
|
|
163
|
+
400: "Cookies are missing";
|
|
164
|
+
401: "Invalid provider" | "No auth provider found" | "No user session found";
|
|
165
|
+
500: `${string} - ${string}` | `Failed to validate authorization code: Unknown error: ${string}`;
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
}) & {}, {
|
|
125
170
|
derive: {
|
|
126
|
-
readonly protectRoute: (handleAuth: () => Promise<Response>, handleAuthFail?: () => Promise<Response>) => Promise<Response | import("elysia/error").ElysiaCustomStatusResponse<"Unauthorized", "No session ID found", 401> | import("elysia/error").ElysiaCustomStatusResponse<"Unauthorized", "No session found", 401>>;
|
|
171
|
+
readonly protectRoute: (handleAuth: () => Promise<Response>, handleAuthFail?: () => Promise<Response>) => Promise<Response | import("elysia/error").ElysiaCustomStatusResponse<"Bad Request", "Cookies are missing", 400> | import("elysia/error").ElysiaCustomStatusResponse<"Unauthorized", "No session ID found", 401> | import("elysia/error").ElysiaCustomStatusResponse<"Unauthorized", "No session found", 401>>;
|
|
127
172
|
};
|
|
128
173
|
resolve: {};
|
|
129
174
|
schema: import("elysia").MergeSchema<{
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Elysia } from 'elysia';
|
|
2
|
+
import { ClientProviders, OnProfile, RouteString } from './types';
|
|
3
|
+
type ProfileProps = {
|
|
4
|
+
clientProviders: ClientProviders;
|
|
5
|
+
profileRoute?: RouteString;
|
|
6
|
+
onProfile?: OnProfile;
|
|
7
|
+
};
|
|
8
|
+
export declare const profile: <UserType>({ clientProviders, profileRoute, onProfile }: ProfileProps) => Elysia<"", {
|
|
9
|
+
decorator: {};
|
|
10
|
+
store: {
|
|
11
|
+
session: import("./types").SessionRecord<UserType>;
|
|
12
|
+
};
|
|
13
|
+
derive: {};
|
|
14
|
+
resolve: {};
|
|
15
|
+
}, {
|
|
16
|
+
error: {};
|
|
17
|
+
typebox: import("@sinclair/typebox").TModule<{}, {}>;
|
|
18
|
+
}, {
|
|
19
|
+
schema: {};
|
|
20
|
+
macro: {};
|
|
21
|
+
macroFn: {};
|
|
22
|
+
parser: {};
|
|
23
|
+
}, {
|
|
24
|
+
[x: string]: {
|
|
25
|
+
get: {
|
|
26
|
+
body: unknown;
|
|
27
|
+
params: {};
|
|
28
|
+
query: unknown;
|
|
29
|
+
headers: unknown;
|
|
30
|
+
response: {
|
|
31
|
+
200: Response;
|
|
32
|
+
400: "Cookies are missing";
|
|
33
|
+
401: "Invalid provider" | "No auth provider found" | "No user session found";
|
|
34
|
+
500: `${string} - ${string}` | `Failed to validate authorization code: Unknown error: ${string}`;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}, {
|
|
39
|
+
derive: {};
|
|
40
|
+
resolve: {};
|
|
41
|
+
schema: {};
|
|
42
|
+
}, {
|
|
43
|
+
derive: {};
|
|
44
|
+
resolve: {};
|
|
45
|
+
schema: {};
|
|
46
|
+
}>;
|
|
47
|
+
export {};
|
|
@@ -16,7 +16,7 @@ export declare const protectRoute: <UserType>() => Elysia<"", {
|
|
|
16
16
|
parser: {};
|
|
17
17
|
}, {}, {
|
|
18
18
|
derive: {
|
|
19
|
-
readonly protectRoute: (handleAuth: () => Promise<Response>, handleAuthFail?: () => Promise<Response>) => Promise<Response | import("elysia/error").ElysiaCustomStatusResponse<"Unauthorized", "No session ID found", 401> | import("elysia/error").ElysiaCustomStatusResponse<"Unauthorized", "No session found", 401>>;
|
|
19
|
+
readonly protectRoute: (handleAuth: () => Promise<Response>, handleAuthFail?: () => Promise<Response>) => Promise<Response | import("elysia/error").ElysiaCustomStatusResponse<"Bad Request", "Cookies are missing", 400> | import("elysia/error").ElysiaCustomStatusResponse<"Unauthorized", "No session ID found", 401> | import("elysia/error").ElysiaCustomStatusResponse<"Unauthorized", "No session found", 401>>;
|
|
20
20
|
};
|
|
21
21
|
resolve: {};
|
|
22
22
|
schema: import("elysia").MergeSchema<{}, {}, "">;
|
package/dist/src/refresh.d.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { Elysia } from 'elysia';
|
|
2
|
-
import { ClientProviders } from './types';
|
|
2
|
+
import { ClientProviders, OnRefresh, RouteString } from './types';
|
|
3
3
|
type RefreshProps = {
|
|
4
4
|
clientProviders: ClientProviders;
|
|
5
|
-
refreshRoute?:
|
|
6
|
-
onRefresh?:
|
|
5
|
+
refreshRoute?: RouteString;
|
|
6
|
+
onRefresh?: OnRefresh;
|
|
7
7
|
};
|
|
8
|
-
export declare const refresh: ({ clientProviders, refreshRoute, onRefresh }: RefreshProps) => Elysia<"", {
|
|
8
|
+
export declare const refresh: <UserType>({ clientProviders, refreshRoute, onRefresh }: RefreshProps) => Elysia<"", {
|
|
9
9
|
decorator: {};
|
|
10
|
-
store: {
|
|
10
|
+
store: {
|
|
11
|
+
session: import("./types").SessionRecord<UserType>;
|
|
12
|
+
};
|
|
11
13
|
derive: {};
|
|
12
14
|
resolve: {};
|
|
13
15
|
}, {
|
|
14
|
-
typebox: import("@sinclair/typebox").TModule<{}>;
|
|
15
16
|
error: {};
|
|
17
|
+
typebox: import("@sinclair/typebox").TModule<{}, {}>;
|
|
16
18
|
}, {
|
|
17
19
|
schema: {};
|
|
18
20
|
macro: {};
|
|
@@ -27,9 +29,10 @@ export declare const refresh: ({ clientProviders, refreshRoute, onRefresh }: Ref
|
|
|
27
29
|
headers: unknown;
|
|
28
30
|
response: {
|
|
29
31
|
200: Response;
|
|
30
|
-
|
|
32
|
+
400: "Cookies are missing" | "Invalid provider" | "No refresh token found";
|
|
33
|
+
401: "Invalid provider" | "No auth provider found" | "No user session found";
|
|
31
34
|
501: "Provider is not refreshable";
|
|
32
|
-
500: `Failed to refresh token: ${string}
|
|
35
|
+
500: `Failed to refresh token: ${string}`;
|
|
33
36
|
};
|
|
34
37
|
};
|
|
35
38
|
};
|
package/dist/src/revoke.d.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { Elysia } from 'elysia';
|
|
2
|
-
import { ClientProviders } from './types';
|
|
2
|
+
import { ClientProviders, OnRevocation, RouteString } from './types';
|
|
3
3
|
type RevokeProps = {
|
|
4
4
|
clientProviders: ClientProviders;
|
|
5
|
-
revokeRoute?:
|
|
6
|
-
|
|
5
|
+
revokeRoute?: RouteString;
|
|
6
|
+
onRevocation?: OnRevocation;
|
|
7
7
|
};
|
|
8
|
-
export declare const revoke: ({ clientProviders, revokeRoute,
|
|
8
|
+
export declare const revoke: <UserType>({ clientProviders, revokeRoute, onRevocation }: RevokeProps) => Elysia<"", {
|
|
9
9
|
decorator: {};
|
|
10
|
-
store: {
|
|
10
|
+
store: {
|
|
11
|
+
session: import("./types").SessionRecord<UserType>;
|
|
12
|
+
};
|
|
11
13
|
derive: {};
|
|
12
14
|
resolve: {};
|
|
13
15
|
}, {
|
|
14
|
-
typebox: import("@sinclair/typebox").TModule<{}>;
|
|
15
16
|
error: {};
|
|
17
|
+
typebox: import("@sinclair/typebox").TModule<{}, {}>;
|
|
16
18
|
}, {
|
|
17
19
|
schema: {};
|
|
18
20
|
macro: {};
|
|
@@ -20,18 +22,17 @@ export declare const revoke: ({ clientProviders, revokeRoute, onRevoke }: Revoke
|
|
|
20
22
|
parser: {};
|
|
21
23
|
}, {
|
|
22
24
|
[x: string]: {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
25
|
+
post: {
|
|
26
|
+
body: unknown;
|
|
27
|
+
params: {};
|
|
28
|
+
query: unknown;
|
|
29
|
+
headers: unknown;
|
|
30
|
+
response: {
|
|
31
|
+
200: Response;
|
|
32
|
+
400: "Cookies are missing" | "Invalid provider";
|
|
33
|
+
401: "Invalid provider" | "No auth provider found" | "No user session found";
|
|
34
|
+
501: "Provider does not support revocation";
|
|
35
|
+
500: `Failed to revoke token: ${string}`;
|
|
35
36
|
};
|
|
36
37
|
};
|
|
37
38
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Elysia } from 'elysia';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { RouteString } from './types';
|
|
3
|
+
type SignOutProps = {
|
|
4
|
+
signoutRoute?: RouteString;
|
|
5
|
+
onSignOut?: () => void;
|
|
5
6
|
};
|
|
6
|
-
export declare const
|
|
7
|
+
export declare const signout: ({ signoutRoute, onSignOut }: SignOutProps) => Elysia<"", {
|
|
7
8
|
decorator: {};
|
|
8
9
|
store: {};
|
|
9
10
|
derive: {};
|
|
@@ -25,8 +26,9 @@ export declare const logout: ({ logoutRoute, onLogout }: LogoutProps) => Elysia<
|
|
|
25
26
|
headers: unknown;
|
|
26
27
|
response: {
|
|
27
28
|
200: Response;
|
|
29
|
+
400: "Cookies are missing";
|
|
28
30
|
401: "No auth provider found";
|
|
29
|
-
500: `Failed to
|
|
31
|
+
500: `Failed to signout: ${string}`;
|
|
30
32
|
};
|
|
31
33
|
};
|
|
32
34
|
};
|
package/dist/src/status.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Elysia } from 'elysia';
|
|
2
|
-
import { ClientProviders } from './types';
|
|
2
|
+
import { ClientProviders, RouteString } from './types';
|
|
3
3
|
type StatusProps = {
|
|
4
4
|
clientProviders: ClientProviders;
|
|
5
|
-
statusRoute?:
|
|
5
|
+
statusRoute?: RouteString;
|
|
6
6
|
onStatus?: () => void;
|
|
7
7
|
};
|
|
8
8
|
export declare const status: <UserType>({ clientProviders, statusRoute, onStatus }: StatusProps) => Elysia<"", {
|
|
@@ -29,6 +29,8 @@ export declare const status: <UserType>({ clientProviders, statusRoute, onStatus
|
|
|
29
29
|
headers: unknown;
|
|
30
30
|
response: {
|
|
31
31
|
200: Response;
|
|
32
|
+
400: "Cookies are missing";
|
|
33
|
+
401: "Invalid provider";
|
|
32
34
|
501: "Provider is not refreshable";
|
|
33
35
|
500: `Error: ${string} - ${string}` | `Unknown Error: ${string}`;
|
|
34
36
|
};
|
package/dist/src/typeGuards.d.ts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
import { OAuth2Tokens } from 'arctic';
|
|
2
|
-
import { providers } from './providers';
|
|
3
|
-
import { Providers } from './types';
|
|
4
|
-
export declare const isRefreshableProvider: (provider: InstanceType<(typeof providers)[Providers]>) => provider is InstanceType<(typeof providers)[Providers]> & {
|
|
5
|
-
refreshAccessToken: () => Promise<OAuth2Tokens>;
|
|
6
|
-
};
|
|
7
|
-
export declare const isRevocableProvider: (provider: InstanceType<(typeof providers)[Providers]>) => provider is InstanceType<(typeof providers)[Providers]> & {
|
|
8
|
-
revokeAccessToken: (token: string) => Promise<void>;
|
|
9
|
-
};
|
|
10
|
-
export declare const isValidProviderKey: (provider: string) => provider is keyof typeof providers;
|
|
11
1
|
export declare const isValidUser: <UserType>(user: unknown) => user is UserType;
|
|
12
2
|
export declare const isNonEmptyString: (str: string | null | undefined) => str is string;
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,59 +1,69 @@
|
|
|
1
|
+
import { CredentialsFor, OAuth2Client, OAuth2TokenResponse, ProviderOption } from 'citra';
|
|
1
2
|
import { Cookie } from 'elysia';
|
|
2
|
-
import { providers } from './providers';
|
|
3
3
|
type SessionData<UserType> = {
|
|
4
4
|
user: UserType;
|
|
5
|
+
accessToken: string;
|
|
6
|
+
refreshToken?: string;
|
|
5
7
|
expiresAt: number;
|
|
6
8
|
};
|
|
7
9
|
type Oauth2ConfigOptions = {
|
|
8
|
-
[
|
|
9
|
-
credentials:
|
|
10
|
-
|
|
10
|
+
[Provider in ProviderOption]?: {
|
|
11
|
+
credentials: CredentialsFor<Provider>;
|
|
12
|
+
scope?: string[];
|
|
11
13
|
searchParams?: [string, string][];
|
|
12
14
|
};
|
|
13
15
|
};
|
|
14
|
-
export type Providers = keyof typeof providers;
|
|
15
16
|
export type SessionRecord<UserType> = Record<string, SessionData<UserType> | undefined>;
|
|
16
17
|
export type UserFunctionProps = {
|
|
17
18
|
authProvider: string;
|
|
18
|
-
userProfile:
|
|
19
|
-
[key: string]: string | undefined;
|
|
20
|
-
};
|
|
19
|
+
userProfile: Record<string, unknown>;
|
|
21
20
|
};
|
|
22
21
|
export type CreateUser<UserType> = ({ userProfile, authProvider }: UserFunctionProps) => Promise<UserType>;
|
|
23
22
|
export type GetUser<UserType> = ({ userProfile, authProvider }: UserFunctionProps) => Promise<UserType | null>;
|
|
24
|
-
export type OnCallback<UserType> = ({ authProvider, userProfile, session, user_session_id }: {
|
|
23
|
+
export type OnCallback<UserType> = ({ authProvider, tokenResponse, userProfile, session, user_session_id }: {
|
|
25
24
|
authProvider: string;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
25
|
+
tokenResponse: OAuth2TokenResponse;
|
|
26
|
+
userProfile: Record<string, unknown>;
|
|
29
27
|
session: SessionRecord<UserType>;
|
|
30
28
|
user_session_id: Cookie<string | undefined>;
|
|
31
29
|
}) => void | Promise<void>;
|
|
30
|
+
export type OnRefresh = ({ tokenResponse }: {
|
|
31
|
+
tokenResponse: OAuth2TokenResponse;
|
|
32
|
+
}) => void | Promise<void>;
|
|
33
|
+
export type OnProfile = ({ userProfile }: {
|
|
34
|
+
userProfile: Record<string, unknown>;
|
|
35
|
+
}) => void | Promise<void>;
|
|
36
|
+
export type OnRevocation = ({ tokenToRevoke }: {
|
|
37
|
+
tokenToRevoke: string;
|
|
38
|
+
}) => void | Promise<void>;
|
|
39
|
+
export type RouteString = `/${string}`;
|
|
40
|
+
export type AuthorizeRoute = `${string}/:provider${'' | `/${string}`}`;
|
|
32
41
|
export type AbsoluteAuthProps<UserType> = {
|
|
33
42
|
config: Oauth2ConfigOptions;
|
|
34
|
-
authorizeRoute?:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
authorizeRoute?: AuthorizeRoute;
|
|
44
|
+
profileRoute?: RouteString;
|
|
45
|
+
callbackRoute?: RouteString;
|
|
46
|
+
refreshRoute?: RouteString;
|
|
47
|
+
revokeRoute?: RouteString;
|
|
48
|
+
signoutRoute?: RouteString;
|
|
49
|
+
statusRoute?: RouteString;
|
|
40
50
|
onAuthorize?: () => void;
|
|
41
51
|
onCallback?: OnCallback<UserType>;
|
|
42
52
|
onStatus?: () => void;
|
|
43
|
-
onRefresh?:
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
onRefresh?: OnRefresh;
|
|
54
|
+
onSignOut?: () => void;
|
|
55
|
+
onRevocation?: OnRevocation;
|
|
56
|
+
onProfile?: OnProfile;
|
|
46
57
|
};
|
|
47
58
|
export type ClientProviders = Record<string, {
|
|
48
|
-
providerInstance:
|
|
49
|
-
|
|
50
|
-
searchParams
|
|
59
|
+
providerInstance: OAuth2Client<ProviderOption>;
|
|
60
|
+
scope?: string[];
|
|
61
|
+
searchParams?: [string, string][];
|
|
51
62
|
}>;
|
|
52
63
|
export type InsantiateUserSessionProps<UserType> = {
|
|
53
64
|
authProvider: string;
|
|
54
|
-
userProfile:
|
|
55
|
-
|
|
56
|
-
};
|
|
65
|
+
userProfile: Record<string, unknown>;
|
|
66
|
+
tokenResponse: OAuth2TokenResponse;
|
|
57
67
|
session: SessionRecord<UserType>;
|
|
58
68
|
user_session_id: Cookie<string | undefined>;
|
|
59
69
|
createUser: () => UserType | Promise<UserType>;
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { AbsoluteAuthProps, InsantiateUserSessionProps } from './types';
|
|
2
|
-
export declare const instantiateUserSession: <UserType>({ user_session_id, session, getUser, createUser }: InsantiateUserSessionProps<UserType>) => Promise<void>;
|
|
2
|
+
export declare const instantiateUserSession: <UserType>({ user_session_id, session, tokenResponse, getUser, createUser }: InsantiateUserSessionProps<UserType>) => Promise<void>;
|
|
3
3
|
export declare const createAuthConfig: <UserType>(props: AbsoluteAuthProps<UserType>) => AbsoluteAuthProps<UserType>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineConfig } from 'drizzle-kit';
|
|
2
|
+
|
|
3
|
+
if (!process.env.DATABASE_URL) {
|
|
4
|
+
throw new Error('DATABASE_URL must be set in the environment variables');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
dialect: 'postgresql',
|
|
9
|
+
dbCredentials: {
|
|
10
|
+
url: process.env.DATABASE_URL
|
|
11
|
+
}
|
|
12
|
+
});
|