Back

[SOLVED] Password Recovery query paramters inserted at wrong position

  • 0
  • Flutter
  • Accounts
Tomic R.
30 Jun, 2023, 13:54

Hello! I am currently in the process of implementing password recovery. I am using Flutter. This is my code to send the recovery email in first place:

TypeScript
 await _account.createRecovery(
          email: email, url: 'http://localhost:5000/#/password-recovery');

However, there is a problem with it. When the mail was sent (I already set up smtp etc.), the url with the query paramters (userId and secret) looks like this: http://localhost:5000/?userId=[userId]&secret=[secret]&expire=[expire]#/password-recovery

Notice, that the query paramters are not after the password-recovery, but directly after the "main" url. Before I even implemented password recovery (confirmation), I had this url just as an example: http://localhost:8080/v1/account/recovery

The URL that I got in the mail looked like this: http://localhost:8080/v1/account/recovery?userId=[userId]&secret=[secret]&expire=[expire]

Notice, that the query paramters are at the right place when using this url.

Anyone knows, what the issue could be?

TL;DR
The issue is that the query parameters are being inserted at the wrong position in the URL when using the Flutter code for password recovery. The query parameters should be after the "/password-recovery" part of the URL, but they are currently being placed directly after the main URL. This is causing the password recovery link to be incorrect. The solution is to use the "usePathUrlStrategy()" function before running the app in Flutter. This function ensures that the URL strategy is set to use the path. Here's an example: ```dart void main() { usePathUrlStrategy(); // Set the URL strategy to use the path
Binyamin
30 Jun, 2023, 14:01

That is because you're using a browser-side navigation.

Binyamin
30 Jun, 2023, 14:01

What framework you're using?

Binyamin
30 Jun, 2023, 14:02

You can see here https://github.com/appwrite/appwrite/blob/master/src/Appwrite/Template/Template.php#L123

That anything with the # will be append at the end of the URL.

Binyamin
30 Jun, 2023, 14:03

This separation into a fragment is done by PHP own parse_url function https://www.php.net/manual/en/function.parse-url.php

Tomic R.
30 Jun, 2023, 14:27

Flutter alongside go_router

Binyamin
30 Jun, 2023, 14:29

Check this to set your router to be using path https://docs.page/csells/go_router/url-path-strategy

like so

TypeScript
  GoRouter.setUrlPathStrategy(UrlPathStrategy.path);

Then you'll be able to send

TypeScript
 await _account.createRecovery(email: email, url: 'http://localhost:5000/password-recovery');
Tomic R.
30 Jun, 2023, 14:30

Well that's interesting, I always wondered why there is a #, but never bothered because it worked great (till now) xD

Tomic R.
30 Jun, 2023, 14:31

Gonna try it

Binyamin
30 Jun, 2023, 14:32

πŸ™‚ This is meant for servers that won't point all request to index file for processing. As Flutter in the web is a frontend.

Then if you have the # its like you're writing

TypeScript
http://localhost:5000/index.html#/password-recovery

And the JS framework will take care of it.

Binyamin
30 Jun, 2023, 14:32

Now most servers knows how to point the whole path to the main file. Like so http://localhost:5000/index.html/password-recovery

Tomic R.
30 Jun, 2023, 14:34

ahh, interesting, thanks

Binyamin
30 Jun, 2023, 14:36

I see that the link I gave you is for the original package.

Binyamin
30 Jun, 2023, 14:37

Now the recommend way is to this

TypeScript
void main() {
  usePathUrlStrategy(); // ‼️ this line
  runApp(ExampleApp());
}

https://docs.flutter.dev/ui/navigation/url-strategies#configuring-the-url-strategy

Tomic R.
30 Jun, 2023, 14:41

yeah, I've also noticed that. But np, I also found the link ^^

Tomic R.
30 Jun, 2023, 14:44

Thank you very much Binyamin, it works now <:appwritepeepo:902865250427215882>

Binyamin
30 Jun, 2023, 14:44

<:appwritefire:823999000330895380>

Tomic R.
30 Jun, 2023, 14:44

[SOLVED] Password Recovery query paramters inserted at wrong position

Drake
30 Jun, 2023, 16:50
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more