我正在嘗試為客戶端實作 supabase 密碼恢復。遺憾的是,我目前無法做到。
我遵循了此頁面上網站中提供的指南
然后我看看這個repo提供的指南
但我無法讓它作業。
這是我的 supabase 身份驗證設定
這是我的 supabase 和 supabaseAuth 初始化
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Supabase.initialize(
url: 'SITEURL',
anonKey:
'ANONKEY',
authCallbackUrlHostname: 'ADDITIONAL AUTH CALLBACK REDIRECT'
);
//initializing supabaseAuth we use it for password recovery
await SupabaseAuth.initialize(
authCallbackUrlHostname: 'ADDITIONAL AUTH CALLBACK REDIRECT ',
);
//runnig the app
runApp(const MyApp());
}
請注意,通過 ADDITIONAL AUTH CALLBACK REDIRECT 我的意思是完整的 (SITEURL ://reset-callback)
這是我的 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" />
<!-- Accepts URIs that begin with YOUR_SCHEME://YOUR_HOST -->
<data
android:scheme="SITEURL"
android:host="//reset-callback" />
</intent-filter>
在應用程式中,我首先導航到一個名為 AuthPage 的頁面,其中有一個按鈕將用戶帶到一個 ResetPage,在那里用戶輸入他的電子郵件并呼叫 resetpassword 方法
Future<void> resetPassword(String email) async {
try {
final response =
await Supabase.instance.client.auth.api.resetPasswordForEmail(
'email',
options: supabase.AuthOptions(
redirectTo: 'Additional Auth Callback Redirect'
)
);
debugPrint('reset response ${response}');
} catch (error) {
message = error.toString();
debugPrint(message);
}
}
它將用戶帶回 AuthPage 中的 AuthPage 我有 StreamBuilder,它監聽 SupabaseAuth.onAuthStateChange,如果 chage 是 passwordRecover,它會顯示一個 TextField 和一個按鈕,供用戶重置他的密碼,如下所示
StreamBuilder(
stream: SupabaseAuth.instance.onAuthChange,
builder: (context, AsyncSnapshot<AuthChangeEvent> snapshot) {
print('snap shot auth state changed to ${snapshot.data.toString()}');
if (snapshot.data == AuthChangeEvent.passwordRecovery) {
return Column(
children: [
const Text('Set New Password'),
TextField(
controller: controller,
decoration: const InputDecoration(
filled: true,
),
),
ElevatedButton(
onPressed: () {
if (controller.text.isEmpty ||
controller.text.length < 8) {
return;
}
Supabase.instance.client.auth
.update(
UserAttributes(password: controller.text.trim()))
.catchError((error) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('ERROR : $error')));
})
.then((value) => Navigator.of(context)
.pushReplacement(MaterialPageRoute(
builder: (ctx) => const AuthScreen())));
},
child: const Text('Submit'),
),
],
);
} else {
SomeOtherWidget(),
}
})
完成所有這些問題后,當我輸入電子郵件并且將恢復鏈接通過電子郵件發送給我時,它什么也沒顯示


我確定用戶存在,因為它顯示在 supabase 的用戶部分
我不知道我做錯了什么,我不知道如何處理識別 url 中的 type=recovery 引數的應用程式。任何幫助將非常感激 。
uj5u.com熱心網友回復:
我通過更改主機名解決了這個問題,結果我在清單中設定錯誤,還有一件事是 supabase 只允許與 io.supabase.whatever 作為主機的深層鏈接
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/381734.html
上一篇:Xamarin-自動登錄
