Created
August 1, 2023 14:38
-
-
Save hieuwu/8bf6b6ce8602ff53a7e89b51eded5c62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AndroidEntryPoint | |
class DeepLinkHandlerActivity : ComponentActivity() { | |
@Inject | |
lateinit var supabaseClient: SupabaseClient | |
private lateinit var callback: (String, String) -> Unit | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
supabaseClient.handleDeeplinks(intent = intent, | |
onSessionSuccess = { userSession -> | |
Log.d("LOGIN", "Log in successfully with user info: ${userSession.user}") | |
userSession.user?.apply { | |
callback(email ?: "", createdAt.toString()) | |
} | |
}) | |
setContent { | |
val navController = rememberNavController() | |
val emailState = remember { mutableStateOf("") } | |
val createdAtState = remember { mutableStateOf("") } | |
LaunchedEffect(Unit) { | |
callback = { email, created -> | |
emailState.value = email | |
createdAtState.value = created | |
} | |
} | |
ManageProductsTheme { | |
Surface( | |
modifier = Modifier.fillMaxSize(), | |
color = MaterialTheme.colorScheme.background | |
) { | |
SignInSuccessScreen( | |
modifier = Modifier.padding(20.dp), | |
navController = navController, | |
email = emailState.value, | |
createdAt = createdAtState.value, | |
onClick = { navigateToMainApp() } | |
) | |
} | |
} | |
} | |
} | |
private fun navigateToMainApp() { | |
val intent = Intent(this, MainActivity::class.java).apply { | |
flags = Intent.FLAG_ACTIVITY_CLEAR_TOP | |
} | |
startActivity(intent) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment