Node.js
Create the Mobile UI
Building the Main Activity
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent { VerifyApp() }
}
}
@Composable
fun VerifyApp() {
MaterialTheme {
Surface(modifier = Modifier.fillMaxSize()) {
VerificationScreen()
}
}
}
ComponentActivity: The base class for activities that use Jetpack Compose.setContent: Sets the UI content using Compose.MaterialThemeandSurface: Wrap the UI in a material design surface for consistency.
Composable Function for Verification Screen
@Composable
fun VerificationScreen() {
var phone by remember { mutableStateOf("") }
var code by remember { mutableStateOf("") }
var message by remember { mutableStateOf("") }
var isLoading by remember { mutableStateOf(false) }
var fallbackToSms by remember { mutableStateOf(false) }
val coroutineScope = rememberCoroutineScope()
Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
OutlinedTextField(
value = phone,
onValueChange = { phone = it },
label = { Text("Phone Number") },
keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Phone),
modifier = Modifier.fillMaxWidth()
)
remember: Allows us to save state across recompositions.coroutineScope: Launches asynchronous operations without blocking the UI.OutlinedTextField: Input field for entering the phone number.
Loading Indicator and Button
if (isLoading) {
CircularProgressIndicator()
} else {
Button(onClick = {
coroutineScope.launch {
isLoading = true
message = "Starting verification..."
try {
val (requestId, authUrl) = startVerification(phone)
currentRequestId = requestId
message = "Verification started!"
} catch (e: Exception) {
message = "Error: ${e.message}"
} finally {
isLoading = false
}
}
}) {
Text("Start Verification")
}
}
Spacer(modifier = Modifier.height(16.dp))
Text(text = message)
}
}
CircularProgressIndicator: Shows a loading spinner while waiting for the response.Button: Starts the verification process.Text: Displays status messages to the user.
Getting Started with Silent Authentication
Silent Authentication takes quite a bit to understand. This tutorial shows you how to build an integration from scratch with Nodejs and Kotlin
Available on:
Steps
1
Introduction2
Before you start3
Initialize the Project4
Create a Simple Express Server5
Setting up Vonage credentials6
Add the Vonage Verify API7
Testing the Backend8
Create New Android Project9
Set up app Android dependencies10
Set up import and constants11
Create Mobile UI12
Networking to Backend13
Testing Full Flow