Skip to content

Commit 59458e0

Browse files
committed
fix: resolve authentication state regressions, restore google sign in
1 parent a89e69a commit 59458e0

File tree

11 files changed

+396
-232
lines changed

11 files changed

+396
-232
lines changed

packages/android/app/src/main/java/io/literal/model/User.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,13 @@ public String getIdentityId() {
157157

158158
public String getEncodedIdentityId() {
159159
String encodedIdentityId = identityId;
160-
try {
161-
encodedIdentityId = URLEncoder.encode(identityId, "UTF-8");
162-
} catch (UnsupportedEncodingException e) {
163-
ErrorRepository.captureException(e);
160+
161+
if (identityId != null) {
162+
try {
163+
encodedIdentityId = URLEncoder.encode(identityId, "UTF-8");
164+
} catch (UnsupportedEncodingException e) {
165+
ErrorRepository.captureException(e);
166+
}
164167
}
165168
return encodedIdentityId;
166169
}

packages/android/app/src/main/java/io/literal/ui/fragment/AppWebView.java

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package io.literal.ui.fragment;
22

3-
import android.app.Activity;
43
import android.content.ActivityNotFoundException;
54
import android.content.Intent;
65
import android.graphics.Bitmap;
76
import android.net.Uri;
87
import android.os.Bundle;
9-
import android.util.Log;
108
import android.view.LayoutInflater;
119
import android.view.View;
1210
import android.view.ViewGroup;
@@ -19,21 +17,16 @@
1917
import androidx.annotation.NonNull;
2018
import androidx.annotation.Nullable;
2119
import androidx.fragment.app.Fragment;
22-
import androidx.fragment.app.FragmentActivity;
2320
import androidx.lifecycle.ViewModelProvider;
2421

25-
import com.amazonaws.mobile.client.results.Tokens;
2622
import com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException;
2723
import com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException;
2824
import com.amazonaws.services.cognitoidentityprovider.model.UsernameExistsException;
29-
import com.apollographql.apollo.json.JsonDataException;
3025

3126
import org.json.JSONException;
3227
import org.json.JSONObject;
3328

3429
import java.io.File;
35-
import java.util.Map;
36-
import java.util.Optional;
3730
import java.util.UUID;
3831

3932
import io.literal.BuildConfig;
@@ -46,7 +39,6 @@
4639
import io.literal.repository.AnalyticsRepository;
4740
import io.literal.repository.ErrorRepository;
4841
import io.literal.repository.SharedPreferencesRepository;
49-
import io.literal.ui.MainApplication;
5042
import io.literal.viewmodel.AppWebViewViewModel;
5143
import io.literal.viewmodel.AuthenticationViewModel;
5244

@@ -103,12 +95,16 @@ private void handleSignInGoogle(io.literal.ui.view.AppWebView view) {
10395
authenticationViewModel.signInGoogle(getActivity(), (e, user) -> {
10496
if (e != null) {
10597
ErrorRepository.captureException(e);
106-
return;
10798
}
10899

109100
try {
110101
JSONObject result = new JSONObject();
111-
result.put("user", user);
102+
if (e == null && !user.isSignedOut()) {
103+
result.put("user", user.toJSON());
104+
} else {
105+
String errorCode = "SIGN_IN_FAILED";
106+
result.put("error", errorCode);
107+
}
112108

113109
getActivity().runOnUiThread(() -> view.postWebEvent(
114110
new WebEvent(WebEvent.TYPE_AUTH_SIGN_IN_GOOGLE_RESULT, UUID.randomUUID().toString(), result)

packages/web/src/Containers/Containers_AnnotationCollectionHeader/Containers_AnnotationCollectionHeader.re

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ let make =
9191
<MaterialUi.IconButton
9292
size=`Small
9393
edge=MaterialUi.IconButton.Edge._end
94-
onClick={_ =>
94+
onClick={_ => {
9595
switch (annotation, identityId) {
9696
| (Some(annotation), Some(identityId)) =>
9797
let _ =
@@ -100,8 +100,8 @@ let make =
100100
);
101101
handleDelete(~annotation, ~identityId);
102102
| _ => ()
103-
}
104-
}
103+
};
104+
}}
105105
_TouchRippleProps={
106106
"classes": {
107107
"child": cn(["bg-white"]),
+1-1
Loading

packages/web/src/constants.re

+20
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,26 @@ let apiOrigin =
1313
Env.amplifyEnv === "production"
1414
? "https://literal.io" : "https://staging.literal.io";
1515

16+
let resetPasswordUrl =
17+
AwsAmplify.Config.(
18+
"https://"
19+
++ awsAmplifyConfig->oauthGet->domainGet
20+
++ "/forgotPassword?"
21+
++ Webapi.Url.URLSearchParams.(
22+
makeWithArray([|
23+
("client_id", awsAmplifyConfig->userPoolsWebClientIdGet),
24+
("response_type", awsAmplifyConfig->oauthGet->responseTypeGet),
25+
(
26+
"scope",
27+
awsAmplifyConfig->oauthGet->scopeGet->Js.Array2.joinWith("+"),
28+
),
29+
("redirect_uri", awsAmplifyConfig->oauthGet->redirectSignInGet),
30+
|])
31+
->toString
32+
->Js.Global.decodeURIComponent
33+
)
34+
);
35+
1636
%raw
1737
{|
1838
const domains = awsAmplifyConfig.oauth.redirectSignIn.split(",")

packages/web/src/routes/Route_Authenticate.re

+2-57
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,5 @@
11
open Styles;
22

3-
let resetPasswordUrl =
4-
AwsAmplify.Config.(
5-
"https://"
6-
++ Constants.awsAmplifyConfig->oauthGet->domainGet
7-
++ "/forgotPassword?"
8-
++ Webapi.Url.URLSearchParams.(
9-
makeWithArray([|
10-
("client_id", Constants.awsAmplifyConfig->userPoolsWebClientIdGet),
11-
(
12-
"response_type",
13-
Constants.awsAmplifyConfig->oauthGet->responseTypeGet,
14-
),
15-
(
16-
"scope",
17-
Constants.awsAmplifyConfig
18-
->oauthGet
19-
->scopeGet
20-
->Js.Array2.joinWith("+"),
21-
),
22-
(
23-
"redirect_uri",
24-
Constants.awsAmplifyConfig->oauthGet->redirectSignInGet,
25-
),
26-
|])
27-
->toString
28-
->Js.Global.decodeURIComponent
29-
)
30-
);
31-
323
[@react.component]
334
let default = () => {
345
let Providers_Authentication.{user} =
@@ -63,7 +34,7 @@ let default = () => {
6334
),
6435
)
6536
);
66-
| (SignedInUser({identityId}), Some(_)) =>
37+
| (SignedInUser(_), Some(_)) =>
6738
setIsAuthenticating(_ => false);
6839
let _ =
6940
Webview.(
@@ -77,24 +48,6 @@ let default = () => {
7748
[|user|],
7849
);
7950

80-
let handleAuthenticateGoogle = () => {
81-
setIsMenuOpen(_ => false);
82-
setIsAuthenticating(_ => true);
83-
let didPostMessage =
84-
Webview.(postMessage(WebEvent.make(~type_="AUTH_SIGN_IN_GOOGLE", ())));
85-
86-
let _ =
87-
if (!didPostMessage) {
88-
AwsAmplify.Auth.(
89-
federatedSignInWithOptions(
90-
inst,
91-
{provider: "Google", customState: None},
92-
)
93-
);
94-
};
95-
();
96-
};
97-
9851
let handleToggleIsMenuOpen = () => setIsMenuOpen(open_ => !open_);
9952

10053
<main
@@ -147,7 +100,7 @@ let default = () => {
147100
(),
148101
)}>
149102
<a
150-
href=resetPasswordUrl
103+
href=Constants.resetPasswordUrl
151104
className={Cn.fromList(["flex", "flex-1", "items-center"])}>
152105
{React.string("Reset Password")}
153106
</a>
@@ -167,14 +120,6 @@ let default = () => {
167120
</a>
168121
</Next.Link>
169122
</MaterialUi.MenuItem>
170-
<MaterialUi.MenuItem
171-
classes={MaterialUi.MenuItem.Classes.make(
172-
~root=Cn.fromList(["font-sans"]),
173-
(),
174-
)}
175-
onClick={_ => handleAuthenticateGoogle()}>
176-
{React.string("Sign in with Google")}
177-
</MaterialUi.MenuItem>
178123
</MaterialUi.Menu>
179124
</MaterialUi.NoSsr>
180125
</div>

0 commit comments

Comments
 (0)