@go-mondo/nextjs-auth 0.1.0

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.
@@ -0,0 +1,201 @@
1
+ import { G as GetAccessTokenOptions, A as AccessTokenResult } from './access-token-UIlXwi3X.js';
2
+ import { SessionOptions, Session } from './session.js';
3
+ import { PartialConfig } from './config.js';
4
+ import { OverrideAuthorizationParams } from './oauth.js';
5
+ import { C as Claims } from './types-CbrOw4QQ.js';
6
+ import 'zod';
7
+
8
+ interface CallbackOptions {
9
+ /**
10
+ * Additional parameters sent to the token endpoint during code exchange.
11
+ */
12
+ tokenParameters?: URLSearchParams | Record<string, string>;
13
+ }
14
+
15
+ type AuthorizationParams = OverrideAuthorizationParams;
16
+ interface LoginOptions {
17
+ /**
18
+ * Override the default authorization parameters for this login request.
19
+ */
20
+ authorization?: Partial<AuthorizationParams>;
21
+ /**
22
+ * URL to return to after login. Overrides the default in {@link BaseConfig.baseURL}.
23
+ */
24
+ returnTo?: string;
25
+ }
26
+
27
+ /**
28
+ * Options for clearing the local session and choosing the post-logout redirect.
29
+ */
30
+ interface LogoutOptions {
31
+ /**
32
+ * Application path to return to after logout.
33
+ */
34
+ returnTo?: string;
35
+ /**
36
+ * If set to `true`, the logout will also log out the user from the identity provider.
37
+ * This is useful for Single Sign Out (SSO) scenarios.
38
+ * If set to `false`, the user will only be logged out from the application.
39
+ * Defaults to `false`.
40
+ */
41
+ singleLogOut?: boolean;
42
+ }
43
+
44
+ interface AccessTokenOptions extends GetAccessTokenOptions {
45
+ /**
46
+ * Optional projection applied before the route returns JSON.
47
+ */
48
+ transform?: (token: AccessTokenResult) => unknown;
49
+ }
50
+
51
+ /**
52
+ * Route-level options used by {@link MondoAuthClient.handleAuth}.
53
+ *
54
+ * Each property customizes the matching built-in route while keeping the same
55
+ * default route mounting behavior.
56
+ */
57
+ type HandleAuthOptions<UserClaims extends Claims = Claims> = {
58
+ /** Options applied to the login route. */
59
+ login?: LoginOptions;
60
+ /** Options applied to the callback route. */
61
+ callback?: CallbackOptions;
62
+ /** Options applied to the logout route. */
63
+ logout?: LogoutOptions;
64
+ /** Options applied to the session JSON route. */
65
+ session?: SessionOptions<UserClaims>;
66
+ /** Options applied to the access-token JSON route. */
67
+ accessToken?: AccessTokenOptions;
68
+ };
69
+ /**
70
+ * Options for protecting requests from Next.js `proxy.ts`.
71
+ */
72
+ type ProxyOptions = {
73
+ /**
74
+ * Paths that should pass through without an authenticated session.
75
+ */
76
+ publicPaths?: Array<string | RegExp>;
77
+ /**
78
+ * A route-specific return URL override for unauthenticated redirects.
79
+ */
80
+ returnTo?: string | ((request: Request) => string | Promise<string>);
81
+ };
82
+ /**
83
+ * Modern entry point for applications. Create one instance in `src/lib/auth.ts`,
84
+ * then reuse it from route handlers, server code, and `proxy.ts`.
85
+ *
86
+ * @typeParam UserClaims - App-specific claims expected on `session.user`.
87
+ */
88
+ declare class MondoAuthClient<UserClaims extends Claims = Claims> {
89
+ private readonly instance;
90
+ /**
91
+ * Creates a client and validates configuration immediately.
92
+ *
93
+ * @param config - Optional explicit config. Environment variables provide the
94
+ * remaining values.
95
+ */
96
+ constructor(config?: PartialConfig);
97
+ /**
98
+ * Validated auth configuration used by this client.
99
+ */
100
+ get config(): {
101
+ authorization: {
102
+ [x: string]: string | number | boolean;
103
+ response_type: "code";
104
+ scope: string;
105
+ response_mode: "query" | "form_post";
106
+ audience?: string | undefined;
107
+ display?: "page" | "popup" | "touch" | "wap" | undefined;
108
+ prompt?: "none" | "login" | "consent" | "select_account" | undefined;
109
+ max_age?: number | undefined;
110
+ ui_locales?: string | undefined;
111
+ id_token_hint?: string | undefined;
112
+ login_hint?: string | undefined;
113
+ acr_values?: string | undefined;
114
+ };
115
+ baseURL: string;
116
+ clientId: string;
117
+ clientSecret: string;
118
+ issuerBaseURL: string;
119
+ secret: string | string[];
120
+ session: {
121
+ name: string;
122
+ idleDuration: number | false;
123
+ absoluteDuration: number | false;
124
+ cookie: {
125
+ path: string;
126
+ httpOnly: boolean;
127
+ sameSite: "none" | "lax" | "strict";
128
+ secure: boolean;
129
+ domain?: string | undefined;
130
+ };
131
+ };
132
+ routes: {
133
+ login: string;
134
+ callback: string;
135
+ logout: string;
136
+ session: string;
137
+ accessToken: string;
138
+ postLogoutRedirect: string;
139
+ };
140
+ transaction: {
141
+ name: string;
142
+ cookie: {
143
+ sameSite: "none" | "lax" | "strict";
144
+ path: string;
145
+ domain?: string | undefined;
146
+ secure?: boolean | undefined;
147
+ };
148
+ };
149
+ };
150
+ /**
151
+ * Returns one route handler that serves all configured auth routes.
152
+ *
153
+ * Mount this from a catch-all route such as
154
+ * `src/app/auth/[...auth]/route.ts`.
155
+ */
156
+ handleAuth(options?: HandleAuthOptions<UserClaims>): (request: Request) => Promise<Response>;
157
+ /**
158
+ * Creates a route handler that starts the OIDC login redirect.
159
+ */
160
+ handleLogin(options?: LoginOptions): (req: Request) => Promise<Response>;
161
+ /**
162
+ * Creates a route handler that completes the OIDC callback.
163
+ */
164
+ handleCallback(options?: CallbackOptions): (req: Request) => Promise<Response>;
165
+ /**
166
+ * Creates a route handler that clears the local session.
167
+ */
168
+ handleLogout(options?: LogoutOptions): (req: Request) => Promise<Response>;
169
+ /**
170
+ * Creates a route handler that returns the current session as JSON.
171
+ */
172
+ handleSession(options?: SessionOptions<UserClaims>): (_req: Request) => Promise<Response>;
173
+ /**
174
+ * Creates a route handler that returns or refreshes the current access token.
175
+ */
176
+ handleAccessToken(options?: AccessTokenOptions): (req: Request) => Promise<Response>;
177
+ /**
178
+ * Reads the current sealed-cookie session in server code.
179
+ */
180
+ getSession: () => Promise<Session<UserClaims> | undefined>;
181
+ /**
182
+ * Returns the current access token, refreshing with the stored refresh token
183
+ * when the token is expired or missing required scopes.
184
+ */
185
+ getAccessToken: (options?: GetAccessTokenOptions) => Promise<AccessTokenResult>;
186
+ /**
187
+ * Drop this into `proxy.ts` to protect matched routes and keep idle sessions
188
+ * fresh at the request boundary.
189
+ */
190
+ proxy: (request: Request, options?: ProxyOptions) => Promise<Response | undefined>;
191
+ }
192
+ /**
193
+ * Creates a configured Mondo auth client.
194
+ *
195
+ * @typeParam UserClaims - App-specific claims expected on `session.user`.
196
+ * @param config - Optional explicit config. Environment variables provide the
197
+ * remaining values.
198
+ */
199
+ declare function createAuth<UserClaims extends Claims = Claims>(config?: PartialConfig): MondoAuthClient<UserClaims>;
200
+
201
+ export { type HandleAuthOptions, MondoAuthClient, type ProxyOptions, createAuth };