英文:
Redirect user back to flutter app for supabase password reset
问题
以下是翻译好的内容:
当用户在密码重置电子邮件中点击"重置电子邮件"链接时,他们会被重定向回我的Flutter应用程序,但不会进入SetNewPasswordScreen。如何确保用户被特定地重定向到SetNewPasswordScreen?
总之,我试图实现以下用户流程:
- 用户在ForgotPasswordScreen上提交他们的电子邮件地址。
- 用户收到电子邮件。
- 用户在电子邮件中点击"重置电子邮件"链接。
- 用户被重定向到SetNewPasswordScreen。
以下调用会触发密码重置电子邮件发送给用户:
final response = await supaClient.auth.resetPasswordForEmail(email,
redirectTo: kIsWeb
? null
: 'io.supabase.pickleballislife://forgotpassword-callback/');
在我的ios/Runner/Info.plist文件中,我插入了以下块:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>'io.supabase.pickleballislife://forgotpassword-callback/'</string>
</array>
</dict>
</array>
在我的android/app/src/main/AndroidManifest.xml文件中,我插入了以下块:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- 接受以YOUR_SCHEME://YOUR_HOST开头的URI -->
<data
android:scheme="io.supabase.pickleballislife"
android:host="forgotpassword-callback" />
</intent-filter>
SetNewPasswordScreen的路由为:
static const ROUTE_NAME = '/forgotpassword-callback';
我已经在我的路由中如下定义它:
SetNewPasswordScreen.ROUTE_NAME: (BuildContext context) {
return SetNewPasswordScreen();
},
在我的ForgotPasswordScreen上,我已设置了以下AuthChangeEvent监听器:
@override
void initState() {
super.initState();
final _authSubscription = supaClient.auth.onAuthStateChange.listen((data) {
final AuthChangeEvent event = data.event;
if (event == AuthChangeEvent.passwordRecovery) {
goToNamed(
SetNewPasswordScreen.ROUTE_NAME,
replace: true,
);
}
});
_authSubscription.cancel();
}
如何确保用户在电子邮件中点击"重置密码"链接后,他们被重定向到SetNewPassword屏幕,而不仅仅是我的移动应用程序?
英文:
I'm fairly new to supabase, flutter, and programming in general. I'm trying to achieve the following:
When the user taps the "Reset Email" link in the password reset email, they are redirected back to my Flutter app, but not to the SetNewPasswordScreen. How can I make sure that the user is redirected to the SetNewPasswordScreen specifically?
In summary, this is the user flow I am trying to achieve:
- User submits their email address on ForgotPasswordScreen
- User recieves email
- User taps "Reset Email" link in email
- User is redirected to SetNewPasswordScreen
The following call triggers the password reset email to be sent to the user:
final response = await supaClient.auth.resetPasswordForEmail(email,
redirectTo: kIsWeb
? null
: 'io.supabase.pickleballislife://forgotpassword-callback/');
In my ios/Runner/Info.plist file, I've inserted the following block:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>'io.supabase.pickleballislife://forgotpassword-callback/'</string>
</array>
</dict>
</array>
And in my android/app/src/main/AndroidManifest.xml file, I've inserted the following block:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with YOUR_SCHEME://YOUR_HOST -->
<data
android:scheme="io.supabase.pickleballislife"
android:host="forgotpassword-callback" />
</intent-filter>
The route for the SetNewPasswordScreen is:
static const ROUTE_NAME = '/forgotpassword-callback';
and I've defined it in my routes the following way:
SetNewPasswordScreen.ROUTE_NAME: (BuildContext context) {
return SetNewPasswordScreen();
},
And on my ForgotPasswordScreen, I've set up the following AuthChangeEvent listener:
@override
void initState() {
super.initState();
final _authSubscription = supaClient.auth.onAuthStateChange.listen((data) {
final AuthChangeEvent event = data.event;
if (event == AuthChangeEvent.passwordRecovery) {
goToNamed(
SetNewPasswordScreen.ROUTE_NAME,
replace: true,
);
}
});
_authSubscription.cancel();
}
How can I ensure that once the user taps the "Reset Password" link in their email, they are redirected to the SetNewPassword screen and not just my mobile app in general?
答案1
得分: 1
Your plist file should contain only io.supabase.pickleballislife
, because that is your scheme
<key>FlutterDeepLinkingEnabled</key>
<true/>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>io.supabase.pickleballislife</string>
</array>
</dict>
</array>
Then instead of going to io.supabase.pickleballislife://forgotpassword-callback/
, you can go to io.supabase.pickleballislife://callback/forgotpassword
. The key is that we are now redirecting to the /forgotpassword
path. BTW, there is nothing wrong with having forgotpassword-callback
as the host, but it might be confusing, so I have changed it to callback
. You may want to update the setting on Android as well.
Now you can setup your routes using GoRouter,
GoRouter(
routes: [
...
GoRoute(
path: '/forgotpassword',
builder: (context, state) => SetNewPasswordScreen(),
),
],
);
You also need to setup some additional configuration on both iOS and Android side to enable Flutter deep linking. You can find the instruction here.
With this, you should be able to call the following and the user will be redirected to the password reset page! Also remember to update the URL configuration on your Supabase dashboard to accept io.supabase.pickleballislife://callback/forgotpassword/
as additional URL.
final response = await supaClient.auth.resetPasswordForEmail(email,
redirectTo: kIsWeb
? null
: 'io.supabase.pickleballislife://callback/forgotpassword/');
英文:
Your plist file should contain only io.supabase.pickleballislife
, because that is your scheme
<key>FlutterDeepLinkingEnabled</key>
<true/>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>io.supabase.pickleballislife</string>
</array>
</dict>
</array>
Then instead of going to io.supabase.pickleballislife://forgotpassword-callback/
, you can go to io.supabase.pickleballislife://callback/forgotpassword
. The key is that we are now redirecting to the /forgotpassword
path. BTW, there is nothing wrong with having forgotpassword-callback
as the host, but it might be confusing, so I have changed it to callback
. You may want to update the setting on Android as well.
Now you can setup your routes using GoRouter,
GoRouter(
routes: [
...
GoRoute(
path: '/forgotpassword',
builder: (context, state) => SetNewPasswordScreen(),
),
],
);
You also need to setup some additional configuration on both iOS and Android side to enable Flutter deep linking. You can find the instruction here.
With this, you should be able to call the following and the user will be redirected to the password reset page! Also remember to update the URL configuration on your Supabase dashboard to accept io.supabase.pickleballislife://callback/forgotpassword/
as additional URL.
final response = await supaClient.auth.resetPasswordForEmail(email,
redirectTo: kIsWeb
? null
: 'io.supabase.pickleballislife://callback/forgotpassword/');
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论