LogOff
📱 Overview
User Log Off functionality allows mobile app users to securely terminate their authenticated session within the application. This is a critical security feature that ensures user sessions are properly closed, preventing unauthorized access to sensitive information.
Purpose
- Securely terminates the user's authenticated session
- Switches the application context from user session back to application session
- Maintains security by properly clearing session data
- Returns the user to the initial login screen
🖥️ User Interface Requirements
When implementing the Log Off functionality, mobile application developers should:
- Provide a clear and accessible "Log Off" or "Sign Out" option in the application's navigation menu, settings, or user profile section
- Show a confirmation dialog before proceeding with log off (recommended but optional)
- Display a loading indicator during the log off process
- After successful log off, redirect users to the initial login screen
- In case of errors, display appropriate error messages to the user
Workflow
flowchart TD userLogsIn[User Logs In] onUserLoggedIn[SDK triggers onUserLoggedIn] dashboardScreen[App shows dashboard screen] logOff[App calls logOff] onUserLoggedOff[SDK triggers onUserLoggedOff] getUser[SDK triggers getUser] loginScreen[App shows login screen] terminate[App calls terminate] onTerminate[SDK triggers onTerminate] userLogsIn --> onUserLoggedIn onUserLoggedIn --> dashboardScreen dashboardScreen -- User wants to log off --> logOff dashboardScreen -- Application Close/Exit --> terminate logOff --> onUserLoggedOff onUserLoggedOff --> getUser getUser --> loginScreen terminate --> onTerminate style onUserLoggedIn fill:#d4fdd4,stroke:#228b22,stroke-width:2px style onUserLoggedOff fill:#d4fdd4,stroke:#228b22,stroke-width:2px style getUser fill:#d4fdd4,stroke:#228b22,stroke-width:2px style onTerminate fill:#d4fdd4,stroke:#228b22,stroke-width:2px style logOff fill:#ffe4b3,stroke:#ff8c00,stroke-width:2px style terminate fill:#ffe4b3,stroke:#ff8c00,stroke-width:2px
🟩 Green - Callbacks issued by REL-ID SDK
🟧 Orange - APIs invoked by the Client App
LogOff API
This API method is used to log off the user session. The status is communicated to the client via the onUserLoggedOff
event issued by the SDK, which also issues a getUser
event to display the initial screen of the application.
React Native
// Import the necessary modules
import RdnaClient from 'react-native-rdna-client';
// Call the logOff method
RdnaClient.logOff(userID, (syncResponse) => {
// Handle sync response if needed
console.log("LogOff sync response:", syncResponse);
});
// Set up event listener for onUserLoggedOff event
let onUserLoggedOffSubscription = rdnaEventRegistery.addListener(
'onUserLoggedOff', (response) => {
// Handle the log off response
console.log("User logged off successfully:", response);
// Navigate to login screen or initial screen
// Example: this.props.navigation.navigate('Login');
}
);
// Don't forget to remove the event listener when component unmounts
componentWillUnmount() {
onUserLoggedOffSubscription.remove();
}
Flutter
import 'package:flutter/material.dart';
import 'package:rdna_plugin/rdna_plugin.dart';
// Call the logOff method
rdnaClient.logOff(userID);
// Set up event listener for onUserLoggedOff event
rdnaClient.on(RdnaClient.onUserLoggedOff, onUserLoggedOff);
// Define the callback function
void onUserLoggedOff(RDNAUserLogOff response) {
// Handle the log off response
print("User logged off successfully");
// Navigate to login screen or initial screen
// Example: Navigator.of(context).pushReplacementNamed('/login');
}
Cordova
// Call the logOff method
com.uniken.rdnaplugin.RdnaClient.logOff(
function(success) {
console.log("LogOff initiated successfully");
},
function(error) {
console.error("Error initiating LogOff:", error);
},
[userID]
);
// Set up event listener for onUserLoggedOff event
document.addEventListener('onUserLoggedOff', onUserLoggedOff);
// Define the callback function
function onUserLoggedOff(response) {
// Handle the log off response
console.log("User logged off successfully:", response);
// Navigate to login screen or initial screen
}
Native iOS
// Objective-C
// Call the logOff method
RDNAError *error = [rdnaClient logOff:userID];
if (error.shortErrorCode != 0) {
// Handle error
NSLog(@"Error initiating LogOff: %@", error.errorString);
}
// Set up event listener for onUserLoggedOff event
- (void)onUserLoggedOff:(RDNAChallengeResponse *)response {
// Handle the log off response
NSLog(@"User logged off successfully");
// Navigate to login screen or initial screen
}
// Swift
// Call the logOff method
let error = rdnaClient.logOff(userID)
if error.shortErrorCode != 0 {
// Handle error
print("Error initiating LogOff: \(error.errorString)")
}
// Set up event listener for onUserLoggedOff event
func onUserLoggedOff(_ response: RDNAChallengeResponse) {
// Handle the log off response
print("User logged off successfully")
// Navigate to login screen or initial screen
}
Native Android
// Call the logOff method
RDNAError error = rdnaClient.logOff(userID);
if (error.getShortErrorCode() != 0) {
// Handle error
Log.e("REL-ID", "Error initiating LogOff: " + error.getErrorString());
}
// Set up event listener for onUserLoggedOff event
void onUserLoggedOff(RDNA.RDNAChallengeResponse response, RDNAError error) {
// Handle the log off response
Log.d("REL-ID", "User logged off successfully");
// Navigate to login screen or initial screen
}
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
userID | String | The unique identifier of the user to log off | Yes |
SDK Event : onUserLoggedOff
onUserLoggedOff
The SDK triggers the onUserLoggedOff
event with the following response structure:
{
"challengeResponse": {
"status": {
"statusCode": 100,
"statusMessage": ""
},
"session": {
"sessionType": 0,
"sessionID": "532VAHLCM3SXXILNGAXDRSNQHHS9NI5IVNJ7DCAVEDDNJNCEJZE6A2E0C4BE2FE505527F468C7AD60A2F1D62787C4D624DC56FB6E08FC6FC1E69"
},
"additionalInfo": {
"DNAProxyPort": 18080,
"isAdUser": 0,
"isDNAProxyLocalHostOnly": 1,
"JWT": "",
"accessTokenInfo": "",
"settings": "",
"mtlsP12Bundle": "",
"configSettings": "",
"loginIDs": [],
"currentWorkFlow": ""
},
"challengeInfo": []
},
"error": {
"longErrorCode": 0,
"shortErrorCode": 0,
"errorString": "Success"
}
}
Key Payload Fields
Field | Description | Possible Values |
---|---|---|
statusCode | Status code of the log off operation | 100 (Success) |
shortErrorCode | Error code if any | 0 (Success) |
errorString | Error message if any | "Success" or error description |
🎬 Actions on Response
On Success:
- The SDK will automatically trigger the
onUserLoggedOff
event - After this event, the SDK will automatically trigger a
getUser
event - The mobile app should:
- Display a success message (optional)
- Navigate to the application's initial login screen
- Clear any cached user data that should not persist after logout
On Failure:
- Display an appropriate error message to the user
- Provide an option to retry the log off operation
- Log the error details for debugging purposes
- If persistent failures occur, consider providing alternative logout options or contact support information
📊 Best Practices
- Always verify that log off completed successfully by checking the status code
- Include log off functionality in a prominent and easily accessible location
- Implement proper error handling to ensure users are not left in a confusing state
- After log off, ensure sensitive data is properly cleared from memory
- Consider implementing auto-logout for security after periods of inactivity
Updated about 2 months ago