1
0
mirror of https://github.com/go-vikunja/app synced 2024-06-01 02:06:51 +00:00

fixed webview login

This commit is contained in:
Benimautner 2024-01-05 23:09:51 +01:00
parent d5b32c7609
commit 1ba7a443e9
2 changed files with 14 additions and 7 deletions

View File

@ -369,6 +369,7 @@ class _LoginPageState extends State<LoginPage> {
vGS.changeUser(newUser, vGS.changeUser(newUser,
token: baseTokenPair.token, base: baseTokenPair.base); token: baseTokenPair.token, base: baseTokenPair.base);
} catch (e) { } catch (e) {
log("failed to change to user by client token");
log(e.toString()); log(e.toString());
} }
setState(() => _loading = false); setState(() => _loading = false);

View File

@ -18,7 +18,8 @@ class LoginWithWebView extends StatefulWidget {
class LoginWithWebViewState extends State<LoginWithWebView> { class LoginWithWebViewState extends State<LoginWithWebView> {
WebViewWidget? webView; WebViewWidget? webView;
WebViewController? webViewController; late WebViewController webViewController;
bool destroyed = false;
@ -55,7 +56,7 @@ class LoginWithWebViewState extends State<LoginWithWebView> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return WillPopScope(child: Scaffold( return WillPopScope(child: Scaffold(
appBar: AppBar(), appBar: AppBar(),
body: webView body: WebViewWidget(controller: webViewController,)
), ),
onWillPop: () async { onWillPop: () async {
String? currentUrl = await webViewController?.currentUrl(); String? currentUrl = await webViewController?.currentUrl();
@ -74,20 +75,25 @@ class LoginWithWebViewState extends State<LoginWithWebView> {
.runJavaScriptReturningResult("JSON.stringify(localStorage);")).toString(); .runJavaScriptReturningResult("JSON.stringify(localStorage);")).toString();
String apiUrl = (await webViewController!.runJavaScriptReturningResult("API_URL")).toString(); String apiUrl = (await webViewController!.runJavaScriptReturningResult("API_URL")).toString();
String token = (await webViewController!.runJavaScriptReturningResult("localStorage['token']")).toString();
if (localStorage.toString() != "{}") { if (localStorage.toString() != "{}") {
apiUrl = apiUrl.replaceAll("\"", ""); apiUrl = apiUrl.replaceAll("\"", "");
token = token.replaceAll("\"", "");
if(!apiUrl.startsWith("http")) { if(!apiUrl.startsWith("http")) {
if(pageLocation.endsWith("/")) if(pageLocation.endsWith("/"))
pageLocation = pageLocation.substring(0,pageLocation.length-1); pageLocation = pageLocation.substring(0,pageLocation.length-1);
apiUrl = pageLocation + apiUrl; apiUrl = pageLocation + apiUrl;
} }
localStorage = localStorage.replaceAll("\\", "");
localStorage = localStorage.substring(1, localStorage.length - 1); if (apiUrl != "null" && token != "null") {
var json = jsonDecode(localStorage);
if (apiUrl != "null" && json["token"] != null) {
BaseTokenPair baseTokenPair = BaseTokenPair( BaseTokenPair baseTokenPair = BaseTokenPair(
apiUrl, json["token"]); apiUrl, token);
if(destroyed)
return true;
destroyed = true;
print("pop now");
Navigator.pop(context, baseTokenPair); Navigator.pop(context, baseTokenPair);
return true; return true;
} }
} }