@robelest/convex-auth 0.0.4-preview.27 → 0.0.4-preview.28
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/README.md +3 -5
- package/dist/bin.js +6488 -1571
- package/dist/browser/index.js +10 -7
- package/dist/browser/locks.js +3 -5
- package/dist/browser/navigation.js +7 -10
- package/dist/browser/runtime.js +35 -33
- package/dist/client/core/types.js +17 -0
- package/dist/client/factors/device.js +26 -19
- package/dist/client/index.js +151 -163
- package/dist/client/runtime/proxy.js +6 -6
- package/dist/client/services/adapters.js +3 -7
- package/dist/client/services/http.js +2 -5
- package/dist/client/services/resolve.js +5 -11
- package/dist/client/services/runtime.js +2 -5
- package/dist/component/_generated/component.d.ts +46 -0
- package/dist/component/index.d.ts +3 -3
- package/dist/component/model.d.ts +25 -25
- package/dist/component/public/identity/sessions.js +38 -1
- package/dist/component/public/identity/tokens.js +81 -3
- package/dist/component/public/identity/verifiers.js +9 -3
- package/dist/component/public.js +3 -3
- package/dist/component/schema.d.ts +320 -320
- package/dist/core/index.d.ts +380 -0
- package/dist/core/index.js +83 -0
- package/dist/otel.d.ts +13 -17
- package/dist/otel.js +39 -49
- package/dist/providers/email.d.ts +2 -2
- package/dist/providers/password.js +8 -16
- package/dist/providers/phone.js +2 -9
- package/dist/server/auth-context.d.ts +204 -0
- package/dist/server/auth-context.js +76 -0
- package/dist/server/auth.d.ts +25 -187
- package/dist/server/auth.js +5 -96
- package/dist/server/componentContext.d.ts +12 -0
- package/dist/server/componentContext.js +1 -0
- package/dist/server/config.js +1 -12
- package/dist/server/constants.js +6 -0
- package/dist/server/contract.d.ts +1 -1
- package/dist/server/core.js +5 -14
- package/dist/server/crypto.js +26 -18
- package/dist/server/db.js +6 -1
- package/dist/server/device.js +88 -78
- package/dist/server/http.d.ts +4 -3
- package/dist/server/http.js +74 -86
- package/dist/server/index.d.ts +2 -1
- package/dist/server/limits.js +22 -15
- package/dist/server/mounts.d.ts +103 -103
- package/dist/server/mutations/account.js +6 -4
- package/dist/server/mutations/invalidate.js +3 -6
- package/dist/server/mutations/oauth.js +86 -88
- package/dist/server/mutations/refresh.js +45 -87
- package/dist/server/mutations/register.js +19 -19
- package/dist/server/mutations/retrieve.js +17 -15
- package/dist/server/mutations/signature.js +9 -13
- package/dist/server/mutations/signin.js +7 -3
- package/dist/server/mutations/signout.js +10 -15
- package/dist/server/mutations/store.js +22 -12
- package/dist/server/mutations/verifier.js +11 -6
- package/dist/server/mutations/verify.js +55 -46
- package/dist/server/oauth/runtime.js +27 -25
- package/dist/server/passkey.js +299 -250
- package/dist/server/prefetch.js +283 -281
- package/dist/server/refresh.js +7 -60
- package/dist/server/runtime.d.ts +82 -206
- package/dist/server/runtime.js +63 -56
- package/dist/server/services/config.js +5 -3
- package/dist/server/services/logger.js +2 -4
- package/dist/server/services/providers.js +2 -4
- package/dist/server/services/refresh.js +2 -4
- package/dist/server/services/resolve.js +15 -14
- package/dist/server/services/signin.js +2 -4
- package/dist/server/sessions.js +32 -33
- package/dist/server/signin.js +177 -142
- package/dist/server/sso/domain.d.ts +20 -68
- package/dist/server/sso/domain.js +444 -413
- package/dist/server/sso/http.js +53 -59
- package/dist/server/sso/oidc.js +94 -80
- package/dist/server/tokens.js +13 -3
- package/dist/server/totp.js +153 -116
- package/dist/server/types.d.ts +2 -2
- package/dist/server/users.js +18 -23
- package/dist/server/utils/cache.js +51 -0
- package/dist/server/utils/dispatch.js +36 -0
- package/dist/server/utils/retry.js +24 -0
- package/dist/server/utils/span.js +32 -0
- package/dist/shared/errors.js +9 -3
- package/dist/shared/log.js +20 -22
- package/package.json +41 -33
package/dist/server/runtime.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { LOG_LEVELS } from "../shared/log.js";
|
|
2
|
-
import { requireEnv } from "./env.js";
|
|
3
|
-
import { siteUrlsFromEnv } from "./url.js";
|
|
4
|
-
import { redirectToParamCookie, useRedirectToParam } from "./cookies.js";
|
|
5
2
|
import { generateRandomString, sha256 } from "./random.js";
|
|
3
|
+
import { createCoreDomains } from "./core.js";
|
|
4
|
+
import { requireEnv } from "./env.js";
|
|
6
5
|
import { log, logError } from "./log.js";
|
|
7
6
|
import { callModifyAccount } from "./mutations/account.js";
|
|
8
7
|
import { callInvalidateSessions } from "./mutations/invalidate.js";
|
|
@@ -14,17 +13,17 @@ import { callRetrieveAccountWithCredentials } from "./mutations/retrieve.js";
|
|
|
14
13
|
import { callVerifierSignature } from "./mutations/signature.js";
|
|
15
14
|
import { callSignOut } from "./mutations/signout.js";
|
|
16
15
|
import { storeArgs, storeImpl } from "./mutations/store.js";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
16
|
+
import { siteUrlsFromEnv } from "./url.js";
|
|
17
|
+
import { redirectToParamCookie, useRedirectToParam } from "./cookies.js";
|
|
19
18
|
import { addAuthRoutes, addOpenIdRoutes, convertErrorsToResponse, createHttpAction, createHttpContext, createHttpRoute, getCookies } from "./http.js";
|
|
20
19
|
import { createOAuthAuthorizationURL, handleOAuthCallback } from "./oauth/runtime.js";
|
|
20
|
+
import { redirectAbsoluteUrl, setURLSearchParam } from "./redirects.js";
|
|
21
21
|
import { encryptSecret } from "./secret.js";
|
|
22
22
|
import { createGroupService } from "./services/group.js";
|
|
23
23
|
import { resolveServerServices } from "./services/resolve.js";
|
|
24
24
|
import { createGroupConnectionDomain } from "./sso/domain.js";
|
|
25
25
|
import { addGroupHttpRuntime } from "./sso/http.js";
|
|
26
26
|
import { ConvexError, v } from "convex/values";
|
|
27
|
-
import { Effect, Match } from "effect";
|
|
28
27
|
import { actionGeneric, internalMutationGeneric } from "convex/server";
|
|
29
28
|
import { serialize } from "cookie";
|
|
30
29
|
|
|
@@ -163,28 +162,25 @@ function Auth(config_) {
|
|
|
163
162
|
if (request.headers.get("Content-Type")?.includes("application/x-www-form-urlencoded")) (await request.formData()).forEach((value, key) => {
|
|
164
163
|
if (typeof value === "string") params.append(key, value);
|
|
165
164
|
});
|
|
166
|
-
|
|
167
|
-
const result =
|
|
165
|
+
try {
|
|
166
|
+
const result = await handleOAuthCallback(providerId, provider, Object.fromEntries(params.entries()), cookies);
|
|
168
167
|
const oauthCookies = result.cookies;
|
|
169
168
|
const { id: profileId, ...profileData } = result.profile;
|
|
170
169
|
const { signature } = result;
|
|
171
|
-
const
|
|
170
|
+
const redirUrl = setURLSearchParam(destinationUrl, "code", await callUserOAuth(ctx, {
|
|
172
171
|
provider: providerId,
|
|
173
172
|
providerAccountId: profileId,
|
|
174
173
|
profile: profileData,
|
|
175
174
|
signature
|
|
176
175
|
}));
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
status: 302,
|
|
184
|
-
headers: redirHeaders
|
|
185
|
-
});
|
|
176
|
+
const redirHeaders = new Headers({ Location: redirUrl });
|
|
177
|
+
redirHeaders.set("Cache-Control", "must-revalidate");
|
|
178
|
+
for (const { name, value, options } of [...oauthCookies, ...maybeRedirectTo !== null ? [maybeRedirectTo.updatedCookie] : []]) redirHeaders.append("Set-Cookie", serialize(name, value, options));
|
|
179
|
+
return new Response(null, {
|
|
180
|
+
status: 302,
|
|
181
|
+
headers: redirHeaders
|
|
186
182
|
});
|
|
187
|
-
}
|
|
183
|
+
} catch (error) {
|
|
188
184
|
logError(error);
|
|
189
185
|
const respHeaders = new Headers({ Location: destinationUrl });
|
|
190
186
|
for (const { name, value, options } of maybeRedirectTo !== null ? [maybeRedirectTo.updatedCookie] : []) respHeaders.append("Set-Cookie", serialize(name, value, options));
|
|
@@ -192,7 +188,7 @@ function Auth(config_) {
|
|
|
192
188
|
status: 302,
|
|
193
189
|
headers: respHeaders
|
|
194
190
|
});
|
|
195
|
-
}
|
|
191
|
+
}
|
|
196
192
|
}
|
|
197
193
|
});
|
|
198
194
|
},
|
|
@@ -230,42 +226,53 @@ function Auth(config_) {
|
|
|
230
226
|
allowExtraProviders: false,
|
|
231
227
|
resolveSsoProtocol: group.resolveGroupConnectionSsoProtocolOrThrow
|
|
232
228
|
});
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
},
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
229
|
+
const handler = {
|
|
230
|
+
redirect: (r) => ({
|
|
231
|
+
kind: "redirect",
|
|
232
|
+
redirect: r.redirect,
|
|
233
|
+
verifier: r.verifier
|
|
234
|
+
}),
|
|
235
|
+
signedIn: (r) => ({
|
|
236
|
+
kind: "signedIn",
|
|
237
|
+
tokens: r.signedIn?.tokens ?? null
|
|
238
|
+
}),
|
|
239
|
+
refreshTokens: (r) => ({
|
|
240
|
+
kind: "signedIn",
|
|
241
|
+
tokens: r.signedIn?.tokens ?? null
|
|
242
|
+
}),
|
|
243
|
+
started: () => ({ kind: "started" }),
|
|
244
|
+
passkeyOptions: (r) => ({
|
|
245
|
+
kind: "passkeyOptions",
|
|
246
|
+
options: r.options,
|
|
247
|
+
verifier: r.verifier
|
|
248
|
+
}),
|
|
249
|
+
totpRequired: (r) => ({
|
|
250
|
+
kind: "totpRequired",
|
|
251
|
+
verifier: r.verifier
|
|
252
|
+
}),
|
|
253
|
+
totpSetup: (r) => ({
|
|
254
|
+
kind: "totpSetup",
|
|
255
|
+
totpSetup: {
|
|
256
|
+
uri: r.uri,
|
|
257
|
+
secret: r.secret,
|
|
258
|
+
totpId: r.totpId
|
|
259
|
+
},
|
|
260
|
+
verifier: r.verifier
|
|
261
|
+
}),
|
|
262
|
+
deviceCode: (r) => ({
|
|
263
|
+
kind: "deviceCode",
|
|
264
|
+
deviceCode: {
|
|
265
|
+
deviceCode: r.deviceCode,
|
|
266
|
+
userCode: r.userCode,
|
|
267
|
+
verificationUri: r.verificationUri,
|
|
268
|
+
verificationUriComplete: r.verificationUriComplete,
|
|
269
|
+
expiresIn: r.expiresIn,
|
|
270
|
+
interval: r.interval
|
|
271
|
+
}
|
|
272
|
+
})
|
|
273
|
+
}[result.kind];
|
|
274
|
+
if (!handler) throw new Error(`Unexpected sign-in result kind: ${result.kind}`);
|
|
275
|
+
return handler(result);
|
|
269
276
|
}
|
|
270
277
|
}),
|
|
271
278
|
signOut: actionGeneric({
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { configDefaults } from "../config.js";
|
|
2
2
|
|
|
3
3
|
//#region src/server/services/config.ts
|
|
4
|
-
|
|
4
|
+
const createAuthConfig = (config_) => {
|
|
5
|
+
return { config: configDefaults(config_) };
|
|
6
|
+
};
|
|
5
7
|
|
|
6
8
|
//#endregion
|
|
7
|
-
export {
|
|
9
|
+
export { createAuthConfig };
|
|
8
10
|
//# sourceMappingURL=config.js.map
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { logMessage } from "../../shared/log.js";
|
|
2
|
-
import { Layer, ServiceMap } from "effect";
|
|
3
2
|
|
|
4
3
|
//#region src/server/services/logger.ts
|
|
5
|
-
|
|
6
|
-
const AuthLoggerLive = Layer.succeed(AuthLoggerService)({ log: (level, ...args) => logMessage("convex-auth", level, args) });
|
|
4
|
+
const createAuthLogger = () => ({ log: (level, ...args) => logMessage("convex-auth", level, args) });
|
|
7
5
|
|
|
8
6
|
//#endregion
|
|
9
|
-
export {
|
|
7
|
+
export { createAuthLogger };
|
|
10
8
|
//# sourceMappingURL=logger.js.map
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { LOG_LEVELS } from "../../shared/log.js";
|
|
2
2
|
import { listAvailableProviders } from "../config.js";
|
|
3
3
|
import { ConvexError } from "convex/values";
|
|
4
|
-
import { Layer, ServiceMap } from "effect";
|
|
5
4
|
|
|
6
5
|
//#region src/server/services/providers.ts
|
|
7
|
-
|
|
8
|
-
const ProviderRegistryLive = (config, logger) => Layer.succeed(ProviderRegistryService)({ getProviderOrThrow: (id, allowExtraProviders = false) => {
|
|
6
|
+
const createProviderRegistry = (config, logger) => ({ getProviderOrThrow: (id, allowExtraProviders = false) => {
|
|
9
7
|
const provider = config.providers.find((configuredProvider) => configuredProvider.id === id) ?? (allowExtraProviders ? config.extraProviders.find((configuredProvider) => configuredProvider.id === id) : void 0);
|
|
10
8
|
if (provider === void 0) {
|
|
11
9
|
const detail = `Provider \`${id}\` is not configured, available providers are ${listAvailableProviders(config, allowExtraProviders)}.`;
|
|
@@ -20,5 +18,5 @@ const ProviderRegistryLive = (config, logger) => Layer.succeed(ProviderRegistryS
|
|
|
20
18
|
} });
|
|
21
19
|
|
|
22
20
|
//#endregion
|
|
23
|
-
export {
|
|
21
|
+
export { createProviderRegistry };
|
|
24
22
|
//# sourceMappingURL=providers.js.map
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { refreshSessionImpl } from "../mutations/refresh.js";
|
|
2
|
-
import { Layer, ServiceMap } from "effect";
|
|
3
2
|
|
|
4
3
|
//#region src/server/services/refresh.ts
|
|
5
|
-
|
|
6
|
-
const AuthRefreshLive = (config) => Layer.succeed(AuthRefreshService)({ refresh: (ctx, args, getProviderOrThrow) => refreshSessionImpl(ctx, args, getProviderOrThrow, config) });
|
|
4
|
+
const createAuthRefresh = (config) => ({ refresh: (ctx, args) => refreshSessionImpl(ctx, args, config) });
|
|
7
5
|
|
|
8
6
|
//#endregion
|
|
9
|
-
export {
|
|
7
|
+
export { createAuthRefresh };
|
|
10
8
|
//# sourceMappingURL=refresh.js.map
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { configDefaults } from "../config.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { Effect, Layer, ServiceMap } from "effect";
|
|
2
|
+
import { createAuthConfig } from "./config.js";
|
|
3
|
+
import { createAuthLogger } from "./logger.js";
|
|
4
|
+
import { createProviderRegistry } from "./providers.js";
|
|
5
|
+
import { createAuthRefresh } from "./refresh.js";
|
|
6
|
+
import { createAuthSignIn } from "./signin.js";
|
|
8
7
|
|
|
9
8
|
//#region src/server/services/resolve.ts
|
|
10
9
|
function resolveServerServices(config) {
|
|
11
10
|
const configValue = configDefaults(config);
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
11
|
+
const logger = createAuthLogger();
|
|
12
|
+
const authConfig = createAuthConfig(config);
|
|
13
|
+
const providerRegistry = createProviderRegistry(configValue, logger);
|
|
14
|
+
const signIn = createAuthSignIn(configValue);
|
|
15
|
+
const refresh = createAuthRefresh(configValue);
|
|
15
16
|
return {
|
|
16
|
-
config:
|
|
17
|
-
logger
|
|
18
|
-
providerRegistry
|
|
19
|
-
signIn
|
|
20
|
-
refresh
|
|
17
|
+
config: authConfig.config,
|
|
18
|
+
logger,
|
|
19
|
+
providerRegistry,
|
|
20
|
+
signIn,
|
|
21
|
+
refresh
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { signInImpl } from "../signin.js";
|
|
2
|
-
import { Layer, ServiceMap } from "effect";
|
|
3
2
|
|
|
4
3
|
//#region src/server/services/signin.ts
|
|
5
|
-
|
|
6
|
-
const AuthSignInLive = (_config) => Layer.succeed(AuthSignInService)({ signIn: (ctx, provider, args, options) => signInImpl(ctx, provider, args, options) });
|
|
4
|
+
const createAuthSignIn = (_config) => ({ signIn: (ctx, provider, args, options) => signInImpl(ctx, provider, args, options) });
|
|
7
5
|
|
|
8
6
|
//#endregion
|
|
9
|
-
export {
|
|
7
|
+
export { createAuthSignIn };
|
|
10
8
|
//# sourceMappingURL=signin.js.map
|
package/dist/server/sessions.js
CHANGED
|
@@ -1,54 +1,53 @@
|
|
|
1
1
|
import { LOG_LEVELS } from "../shared/log.js";
|
|
2
|
-
import { envOptionalNumber, readConfigSync } from "./env.js";
|
|
3
2
|
import { authDb } from "./db.js";
|
|
3
|
+
import { envOptionalNumber, readConfigSync } from "./env.js";
|
|
4
4
|
import { log, maybeRedact } from "./log.js";
|
|
5
|
-
import { REFRESH_TOKEN_DIVIDER,
|
|
5
|
+
import { REFRESH_TOKEN_DIVIDER, refreshTokenExpirationTime } from "./refresh.js";
|
|
6
6
|
import { TOKEN_SUB_CLAIM_DIVIDER, generateToken } from "./tokens.js";
|
|
7
7
|
|
|
8
8
|
//#region src/server/sessions.ts
|
|
9
9
|
const DEFAULT_SESSION_TOTAL_DURATION_MS = 1e3 * 60 * 60 * 24 * 30;
|
|
10
|
+
const sessionExpirationTime = (config, now = Date.now()) => now + (config.session?.totalDurationMs ?? readConfigSync(envOptionalNumber("AUTH_SESSION_TOTAL_DURATION_MS")) ?? DEFAULT_SESSION_TOTAL_DURATION_MS);
|
|
11
|
+
const encodeRefreshToken = (refreshTokenId, sessionId) => `${refreshTokenId}${REFRESH_TOKEN_DIVIDER}${sessionId}`;
|
|
10
12
|
/** @internal */
|
|
11
|
-
async function maybeGenerateTokensForSession(
|
|
13
|
+
async function maybeGenerateTokensForSession(config, args, generateTokens) {
|
|
12
14
|
return {
|
|
13
|
-
userId,
|
|
14
|
-
sessionId,
|
|
15
|
-
tokens: generateTokens ? await generateTokensForSession(
|
|
16
|
-
userId,
|
|
17
|
-
sessionId,
|
|
18
|
-
|
|
19
|
-
parentRefreshTokenId: null
|
|
15
|
+
userId: args.userId,
|
|
16
|
+
sessionId: args.sessionId,
|
|
17
|
+
tokens: generateTokens && args.refreshTokenId !== void 0 ? await generateTokensForSession(config, {
|
|
18
|
+
userId: args.userId,
|
|
19
|
+
sessionId: args.sessionId,
|
|
20
|
+
refreshTokenId: args.refreshTokenId
|
|
20
21
|
}) : null
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
24
|
/** @internal */
|
|
24
|
-
async function
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
async function issueSession(ctx, config, args) {
|
|
26
|
+
const issued = await authDb(ctx, config).sessions.issue({
|
|
27
|
+
userId: args.userId,
|
|
28
|
+
sessionId: args.existingSessionId,
|
|
29
|
+
replaceSessionId: args.replaceSessionId,
|
|
30
|
+
sessionExpirationTime: sessionExpirationTime(config),
|
|
31
|
+
refreshTokenExpirationTime: args.generateTokens ? refreshTokenExpirationTime(config) : void 0
|
|
32
|
+
});
|
|
33
|
+
return await maybeGenerateTokensForSession(config, {
|
|
34
|
+
userId: issued.userId,
|
|
35
|
+
sessionId: issued.sessionId,
|
|
36
|
+
refreshTokenId: issued.refreshTokenId
|
|
37
|
+
}, args.generateTokens);
|
|
32
38
|
}
|
|
33
39
|
/** @internal */
|
|
34
|
-
async function generateTokensForSession(
|
|
35
|
-
const ids = {
|
|
36
|
-
userId: args.userId,
|
|
37
|
-
sessionId: args.sessionId
|
|
38
|
-
};
|
|
39
|
-
const refreshTokenId = args.issuedRefreshTokenId ?? await createRefreshToken(ctx, config, args.sessionId, args.parentRefreshTokenId);
|
|
40
|
+
async function generateTokensForSession(config, args) {
|
|
40
41
|
const result = {
|
|
41
|
-
token: await generateToken(
|
|
42
|
-
|
|
42
|
+
token: await generateToken({
|
|
43
|
+
userId: args.userId,
|
|
44
|
+
sessionId: args.sessionId
|
|
45
|
+
}, config),
|
|
46
|
+
refreshToken: encodeRefreshToken(args.refreshTokenId, args.sessionId)
|
|
43
47
|
};
|
|
44
|
-
log(LOG_LEVELS.DEBUG, `Generated token ${maybeRedact(result.token)} and refresh token ${maybeRedact(refreshTokenId)} for session ${maybeRedact(args.sessionId)}`);
|
|
48
|
+
log(LOG_LEVELS.DEBUG, `Generated token ${maybeRedact(result.token)} and refresh token ${maybeRedact(args.refreshTokenId)} for session ${maybeRedact(args.sessionId)}`);
|
|
45
49
|
return result;
|
|
46
50
|
}
|
|
47
|
-
async function createSession(ctx, userId, config) {
|
|
48
|
-
const db = authDb(ctx, config);
|
|
49
|
-
const expirationTime = Date.now() + (config.session?.totalDurationMs ?? readConfigSync(envOptionalNumber("AUTH_SESSION_TOTAL_DURATION_MS")) ?? DEFAULT_SESSION_TOTAL_DURATION_MS);
|
|
50
|
-
return await db.sessions.create(userId, expirationTime);
|
|
51
|
-
}
|
|
52
51
|
/** @internal */
|
|
53
52
|
async function deleteSession(ctx, session, config) {
|
|
54
53
|
const db = authDb(ctx, config);
|
|
@@ -69,5 +68,5 @@ async function getAuthSessionId(ctx) {
|
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
//#endregion
|
|
72
|
-
export {
|
|
71
|
+
export { deleteSession, generateTokensForSession, getAuthSessionId, issueSession };
|
|
73
72
|
//# sourceMappingURL=sessions.js.map
|