Arguments
The ID of the user
The tags associated with the session to be created. Leave empty if using defaults. See the Session Tags documentation for more information
Information about the user agent, such as their OS. See the docs here for more information.
The user's IP Address. Including this value will include the user's IP address in the session audit logs. It is also required if you have IP Address restrictions configured. See the docs here for more information.
Additional information to store about the user session.
Link the session to a specific device. See the Device Registration docs for more information.
Successful Response
The ID of the created session
The token for the created session
The Unix timestamp when the session expires
Whether a new device was detected (only present when using device registration)
Error Types
The user has exceeded the maximum number of allowed active sessions
The provided IP address is either on your blocklist, not allowed, or not specified when it should be
The tags provided could not be parsed
The device registration data provided was invalid
An unexpected error occurred during the operation
const auth = createClient({ url, integrationKey });
const result = await auth.session.create({ userId: "1189c444-8a2d-4c41-8b4b-ae43ce79a492", tags: [ "type:high_security" ], userAgent: "Mozilla/5.0 (Macintosh...", ipAddress: "136.38.37.199", metadata: { "example": "value" }, deviceRegistration: { signedDeviceChallenge: "eyJhbGciOiJF..", rememberDevice: true, requestMethod: "POST", requestUrl: "https://api.example.com/api/user", },});
if (result.ok) { console.log("Session created successfully"); // Use result.data.sessionToken for authentication res.cookie("session", result.data.sessionToken);} else { console.log(`Error: ${result.error}`); // Check result.error.type to handle specific errors}client = create_client(url=url, integration_key=integration_key)
result = await client.session.create( user_id="1189c444-8a2d-4c41-8b4b-ae43ce79a492", tags=[ "type:high_security" ], user_agent="Mozilla/5.0 (Macintosh...", ip_address="136.38.37.199", metadata={ "example": "value" }, device_registration={ "signed_device_challenge": "eyJhbGciOiJF..", "remember_device": True, "request_method": "POST", "request_url": "https://api.example.com/api/user", },)
if is_ok(result): print("Session created successfully") # Use result.data.session_token for authentication response.set_cookie("session", result.data.session_token)else: print(f"Error: {result.error}") # Check result.error.type to handle specific errorsPropelAuthClient client = PropelAuthClient.create(url, integrationKey);
CreateSessionCommand command = CreateSessionCommand.builder() .userId("1189c444-8a2d-4c41-8b4b-ae43ce79a492") .tags(Arrays.asList("type:high_security")) .userAgent("Mozilla/5.0 (Macintosh...") .ipAddress("136.38.37.199") .metadata(JsonValue.of(Map.of("example", "value"))) .deviceRegistration(DeviceRegistration.builder() .signedDeviceChallenge("eyJhbGciOiJF..") .rememberDevice(true) .requestMethod("POST") .requestUrl("https://api.example.com/api/user") .build()) .build();
try { CreateSessionResponse sessionResponse = client.session.create(command); System.out.println("Session created successfully"); // Use sessionResponse.getSessionToken() for authentication response.addCookie(new Cookie("session", sessionResponse.getSessionToken()));} catch (CreateSessionException.SessionLimitExceeded e) { System.out.println("Session limit exceeded: " + e.getDetails().getMaxAllowed());} catch (CreateSessionException e) { System.out.println("Error: " + e.getMessage());}var client = new PropelAuthClient(new PropelAuthOptions { Url = url, IntegrationKey = integrationKey });
var command = new CreateSessionCommand{ UserId = "1189c444-8a2d-4c41-8b4b-ae43ce79a492", Tags = new List<string> { "type:high_security" }, UserAgent = "Mozilla/5.0 (Macintosh...", IpAddress = "136.38.37.199", Metadata = JsonSerializer.SerializeToElement(new Dictionary<string, object> { { "example", "value" } }), DeviceRegistration = new DeviceRegistration { SignedDeviceChallenge = "eyJhbGciOiJF..", RememberDevice = true, RequestMethod = "POST", RequestUrl = "https://api.example.com/api/user" }};
try{ var sessionResponse = await client.Session.CreateAsync(command); Console.WriteLine("Session created successfully"); // Use sessionResponse.SessionToken for authentication response.Cookies.Append("session", sessionResponse.SessionToken);}catch (CreateSessionException.SessionLimitExceeded ex){ Console.WriteLine($"Session limit exceeded: {ex.Details.MaxAllowed}");}catch (CreateSessionException ex){ Console.WriteLine($"Error: {ex.Message}");}{ ok: true, data: { sessionId: "vNCf0b...", sessionToken: "sess_vNCf0boJ...", expiresAt: 1735689600, newDeviceDetected: true }}Result( data=CreateSessionResponse( session_id="vNCf0b...", session_token="sess_vNCf0boJ...", expires_at=1735689600, new_device_detected=True ))CreateSessionResponse( sessionId="vNCf0b...", sessionToken="sess_vNCf0boJ...", expiresAt=1735689600, newDeviceDetected=true)CreateSessionResponse{ SessionId = "vNCf0b...", SessionToken = "sess_vNCf0boJ...", ExpiresAt = 1735689600, NewDeviceDetected = true}