Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define Model for Supabase authentication #25

Merged
merged 43 commits into from
Oct 15, 2024
Merged

Conversation

coaguila
Copy link
Contributor

Define Model for Supabase authentication

Description:

This PR introduces new features related to authentication, along with corresponding unit tests.

Key Changes:

  1. Authentication Model:

    • Added AuthModel.kt for handling authentication processes. This file includes logic for user authentication, token management, and user session handling.
    • Implemented support for Supabase authentication via AuthModelSupabase.kt to integrate with Supabase's backend services.
  2. Plugin Manager wrapper:

    • Implemented a wrapper for the SupabaseClient.pluginManager for testing purposes. This does not change the behavior, just allows mocking on the client.
  3. Unit Tests:
    Created unit tests to verify the functionality of the authentication model and plugin manager:

    • Authentication logic validation.
    • Error handling scenarios for failed authentication attempts.
    • Correct plugin loading and management behavior.
    • Supabase integration and session persistence.

Improvements:

We could implement authentication via a third party like Google.

francelu and others added 30 commits October 3, 2024 14:14
Changed the app name from SampleApp to PeriodPals and cascaded the change throughout.
Added basic dependencies as well as Supabase dependencies.
Updated Kotlin version from 1.9.0 to 2.0.0-RC1 for compatibility with kotlinx.serialization.Serializable.
`ExampleRobolectricTest` was acting up because of a reference to a useless second activity that was deleted.
Kept the commented out code as example.
Created interface `com.android.periodpals.model.auth.AuthModel`.
For now, it has three functions: `login`, `register` and `logout`. They can be called from the View Model with an email and a password (except `logout` which does not take arguments).
Created class `com.android.periodpals.model.auth.AuthModelSupabase`, implementing interface `AuthModel`.
It overrides every function from its interface.
Changed the functions' signatures in `AuthModel` and `AuthModelSupabase`.
…ct `onFailure` signature

Added `isUserLoggedIn` function in `AuthModel`. Changed the `onFailure` lambdas' signature to take an `Exception` as argument instead of an `Error`.
…k if user logged in method

Surrounded calls on Supabase client with `try-catch` and use newly added `onSuccess` and `onFailure` lambdas.
Implemented `isUserLoggedIn` function to check whether or not the user is logged in. Takes into account session timeout.
… purposes

The `SupabaseClient` was impossible to mock because of the dependencies coming from the plugins. Therefore, I added a wrapper to the Supabase `PluginManager` that for now is only useful for the `Auth` plugin.
 Also implemented its use in `AuthModelSupabase`.
For now, `register success`, `login success` and `isUserLoggedIn success` do not work because of mocking issues.
Used the mocking functions properly on call to `signUpWith`.
Changed the argument matcher for a nullable argument from `any` to `anyOrNull`.
Used the mocking functions properly on call to `signInWith`.
charliemangano and others added 7 commits October 12, 2024 12:09
Deleted problematic `ExampleInstrumentedTest.kt` and `ExampleRobolectricTest.kt` as they were imported from the Sample App we started from.
…iodpals into feat/authentication/model

# Conflicts:
#	app/src/main/java/com/android/periodpals/MainActivity.kt
@Harrish92 Harrish92 assigned Harrish92 and unassigned Harrish92 Oct 13, 2024
…hentication/model

# Conflicts:
#	gradle/libs.versions.toml
@coaguila coaguila requested review from charliemangano and lazarinibruno and removed request for charliemangano October 14, 2024 11:32
@charliemangano charliemangano removed their assignment Oct 14, 2024
Copy link
Contributor

@lazarinibruno lazarinibruno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool stuff

  • Amazing tests! I like the structure of the tests, checking whether each function of the Model works as expected both in successful and unsuccessful scenarios.
  • Code runs locally

Improvements

  • Adding some comments to the code would imporve readability and improve the review process :3

Steps before merge

LGTM

Copy link
Member

@agonzalez-r agonzalez-r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice work!

Comments

  • Besides, changing the error messages for Log.e I think there is no further improvements at this stage
  • Very clean implementation: PluginManagerWrapper
  • Excellent tests using Mockito

Improvements

  • Changing the return type of the function isUserLoggedIn to boolean?

Steps before merge

LGTM

Log.d(TAG, "register: successfully registered the user")
onSuccess()
} catch (e: Exception) {
Log.d(TAG, "register: failed to register the user: ${e.message}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: use Log.e for errors for better readability of the logs. Check documentation

@charliemangano charliemangano self-assigned this Oct 15, 2024
…hentication/model

# Conflicts:
#	app/build.gradle.kts
@coaguila coaguila merged commit 196ee1b into main Oct 15, 2024
2 checks passed
@charliemangano charliemangano deleted the feat/authentication/model branch October 15, 2024 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Define Model for Supabase authentication
7 participants