Skip to content
This repository has been archived by the owner on May 13, 2023. It is now read-only.

fix: redirect_to double URL encoding issue #102

Merged
merged 2 commits into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions lib/src/gotrue_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,12 @@ class GoTrueClient {
'email': email,
'gotrue_meta_security': {'captcha_token': captchaToken},
};
final urlParams = <String, String>{};
if (redirectTo != null) {
final encodedRedirectTo = Uri.encodeComponent(redirectTo);
urlParams['redirect_to'] = encodedRedirectTo;
}

final fetchOptions =
GotrueRequestOptions(headers: _headers, body: body, query: urlParams);
final fetchOptions = GotrueRequestOptions(
headers: _headers,
body: body,
redirectTo: redirectTo,
);
await _fetch.request(
'$_url/recover',
RequestMethodType.post,
Expand Down Expand Up @@ -501,8 +499,7 @@ class GoTrueClient {
urlParams['scopes'] = scopes;
}
if (redirectTo != null) {
final encodedRedirectTo = Uri.encodeComponent(redirectTo);
urlParams['redirect_to'] = encodedRedirectTo;
urlParams['redirect_to'] = redirectTo;
}
if (queryParams != null) {
urlParams.addAll(queryParams);
Expand Down
8 changes: 8 additions & 0 deletions test/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,14 @@ void main() {
expect(res.provider, Provider.google);
});

test('signIn() with Provider with redirectTo', () async {
final res = await client.getOAuthSignInUrl(
provider: Provider.google, redirectTo: 'https://supabase.com');
expect(res.url,
'$gotrueUrl/authorize?provider=google&redirect_to=https%3A%2F%2Fsupabase.com');
expect(res.provider, Provider.google);
});

test('signIn() with Provider can append a redirectUrl', () async {
final res = await client.getOAuthSignInUrl(
provider: Provider.google,
Expand Down