Skip to content

Time Range Policy

The time range policy allows you to set temporal boundaries for session key permissions. This ensures that session keys can only be used within specific time windows, providing an additional layer of security through time-based access control.

⚠️ Security Consideration: Always set reasonable time bounds and consider your application's specific needs when determining session validity periods.

timeRange.ts
import { usersNexusClient } from "./client.ts";
 
const createSessionsResponse = await usersNexusClient.grantPermission({
  sessionRequestedInfo: [
    {
      sessionPublicKey,
      sessionValidAfter: 0, // Applies to all userOperations
      sessionValidUntil: Date.now() + (365 * 24 * 60 * 60 * 1000), // 1 year from now, applies to all userOperations
      actionPoliciesInfo: [
        {
          abi: DailyTaskAbi,
          contractAddress: "0x...",
          // Session valid for 7 days starting tomorrow
          validAfter: Date.now() + (1 * 24 * 60 * 60 * 1000), // Starts tomorrow
          validUntil: Date.now() + (7 * 24 * 60 * 60 * 1000), // Ends after 7 days
        }
      ]
    }
  ]
});

Common Use Cases

  • Business Hours Access: Restrict session usage to working hours
  • Time-Limited Trials: Grant temporary access for evaluation periods
  • Scheduled Maintenance: Allow access only during maintenance windows
  • Periodic Tasks: Enable automated actions at specific times

Best Practices

  1. Always set both validAfter and validUntil for bounded session lifetimes
  2. Use daily time windows for recurring access patterns
  3. Combine with other policies for comprehensive security
  4. Consider timezone implications when setting time bounds