-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #596 from supabase-community/auth-exceptions
Handle `weak_password` and `session_not_found` auth error codes
- Loading branch information
Showing
7 changed files
with
98 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import io.github.jan.supabase.SupabaseClient | |
import io.github.jan.supabase.exceptions.HttpRequestException | ||
import io.github.jan.supabase.exceptions.RestException | ||
import io.github.jan.supabase.gotrue.admin.AdminApi | ||
import io.github.jan.supabase.gotrue.exception.AuthWeakPasswordException | ||
import io.github.jan.supabase.gotrue.mfa.MfaApi | ||
import io.github.jan.supabase.gotrue.providers.AuthProvider | ||
import io.github.jan.supabase.gotrue.providers.ExternalAuthConfigDefaults | ||
|
@@ -79,12 +80,14 @@ sealed interface Auth : MainPlugin<AuthConfig>, CustomSerializationPlugin { | |
* | ||
* Example: | ||
* ```kotlin | ||
* val result = gotrue.signUpWith(Email) { | ||
* val result = auth.signUpWith(Email) { | ||
* email = "[email protected]" | ||
* password = "password" | ||
* } | ||
* ``` | ||
* or | ||
* gotrue.signUpWith(Google) // Opens the browser to login with google | ||
* ```kotlin | ||
* auth.signUpWith(Google) // Opens the browser to login with google | ||
* ``` | ||
* | ||
* @param provider the provider to use for signing up. E.g. [Email], [Phone] or [Google] | ||
|
@@ -94,6 +97,7 @@ sealed interface Auth : MainPlugin<AuthConfig>, CustomSerializationPlugin { | |
* @throws RestException or one of its subclasses if receiving an error response | ||
* @throws HttpRequestTimeoutException if the request timed out | ||
* @throws HttpRequestException on network related issues | ||
* @throws AuthWeakPasswordException if using the [Email] or [Phone] provider and the password is too weak. You can get the reasons via [AuthWeakPasswordException.reasons] | ||
*/ | ||
suspend fun <C, R, Provider : AuthProvider<C, R>> signUpWith( | ||
provider: Provider, | ||
|
@@ -106,12 +110,14 @@ sealed interface Auth : MainPlugin<AuthConfig>, CustomSerializationPlugin { | |
* | ||
* Example: | ||
* ```kotlin | ||
* val result = gotrue.signInWith(Email) { | ||
* val result = auth.signInWith(Email) { | ||
* email = "[email protected]" | ||
* password = "password" | ||
* } | ||
* ``` | ||
* or | ||
* gotrue.signInWith(Google) // Opens the browser to login with google | ||
* ```kotlin | ||
* auth.signInWith(Google) // Opens the browser to login with google | ||
* ``` | ||
* | ||
* @param provider the provider to use for signing in. E.g. [Email], [Phone] or [Google] | ||
|
This file contains 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
This file contains 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
12 changes: 12 additions & 0 deletions
12
GoTrue/src/commonMain/kotlin/io/github/jan/supabase/gotrue/exception/AuthRestException.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.github.jan.supabase.gotrue.exception | ||
|
||
import io.github.jan.supabase.exceptions.RestException | ||
|
||
/** | ||
* Base class for rest exceptions thrown by the Auth API. | ||
*/ | ||
open class AuthRestException(errorCode: String, message: String): RestException( | ||
error = errorCode, | ||
description = null, | ||
message = message | ||
) |
15 changes: 15 additions & 0 deletions
15
.../commonMain/kotlin/io/github/jan/supabase/gotrue/exception/AuthSessionMissingException.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.github.jan.supabase.gotrue.exception | ||
|
||
/** | ||
* Exception thrown when a session is not found. | ||
*/ | ||
class AuthSessionMissingException: AuthRestException( | ||
errorCode = CODE, | ||
message = "Session not found. This can happen if the user was logged out or deleted." | ||
) { | ||
|
||
internal companion object { | ||
const val CODE = "session_not_found" | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...rc/commonMain/kotlin/io/github/jan/supabase/gotrue/exception/AuthWeakPasswordException.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.github.jan.supabase.gotrue.exception | ||
|
||
/** | ||
* Exception thrown when a session is not found. | ||
* @param description The description of the exception. | ||
* @param reasons The reasons why the password is weak. | ||
*/ | ||
class AuthWeakPasswordException( | ||
description: String, | ||
val reasons: List<String> | ||
) : AuthRestException( | ||
CODE, | ||
description, | ||
) { | ||
|
||
internal companion object { | ||
const val CODE = "weak_password" | ||
} | ||
|
||
} |
This file contains 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