feat(sync): round trip cloud snapshots
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
export interface ElyKvNamespace {
|
||||
get(key: string): Promise<string | null>;
|
||||
put(key: string, value: string): Promise<void>;
|
||||
delete(key: string): Promise<void>;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { AuthContext } from "./auth.js";
|
||||
import { authSessionCacheKvKey } from "./auth.js";
|
||||
import type { Env } from "./bindings.js";
|
||||
import {
|
||||
type DeviceApprovalDocument,
|
||||
@@ -227,6 +228,7 @@ export async function registerDeviceDocument(
|
||||
throw new DevicePersistenceError("device_registration_missing");
|
||||
}
|
||||
await bindSessionDeviceContext(env, context, registration.deviceId, nowSeconds);
|
||||
await refreshSessionDeviceCache(env, context, registration.deviceId);
|
||||
|
||||
return {
|
||||
version: 1,
|
||||
@@ -246,6 +248,23 @@ async function bindSessionDeviceContext(
|
||||
.run();
|
||||
}
|
||||
|
||||
async function refreshSessionDeviceCache(
|
||||
env: Env,
|
||||
context: AuthContext,
|
||||
deviceId: string,
|
||||
): Promise<void> {
|
||||
await env.ELY_KV.put(
|
||||
authSessionCacheKvKey(env.ELY_ENVIRONMENT, context.tokenHash),
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
user_id: context.userId,
|
||||
session_id: context.sessionId,
|
||||
device_id: deviceId,
|
||||
expires_at: context.expiresAt,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function approveDeviceDocument(
|
||||
request: Request,
|
||||
env: Env,
|
||||
|
||||
Reference in New Issue
Block a user