Conversation
foxish
left a comment
There was a problem hiding this comment.
This doesn't work when trying to log out of staging. Please test your code for bugs: https://www.loom.com/share/ec7dc29941544111bfa5388a1fb8a174
src/contexts/AuthContext.tsx
Outdated
|
|
||
| const resetAuth = () => { | ||
| setAuthState(undefined); | ||
| setIsLoading(true); |
There was a problem hiding this comment.
This seems odd to me, does isLoading actually need to be a state variable, or can it actually be computed on the fly?
There was a problem hiding this comment.
It's a state so we can show a loading while we try to fetch the user
There was a problem hiding this comment.
Ok - makes sense. I think it's just feeling a bit overloaded when we use the same state to mean: signed out as well as "sign-in in progress". I don't feel strongly here, but it might be nice to actually separate out more states like:
type AuthStatus =
| 'clear' // no auth creds
| 'loading' // in the middle of a login request
| 'success' // authed and valid
| 'error'; // any failure during login or logout
There was a problem hiding this comment.
Another idea is to do what we do on the web app side - that also seems to do some grouping:
| const cleanPreviewUrl = unsavedValues.previewUrl.replace(/\/+$/, ""); | ||
| const cleanDashboardUrl = unsavedValues.dashboardUrl.replace(/\/+$/, ""); | ||
|
|
||
| // If there is a new apiUrl, we need to reset the auth state |
There was a problem hiding this comment.
I think we can use a more robust mechanism like https://github.com/braintree/sanitize-url rather than just trimming the string. WDYT?
I actually tested this case too and seems fine to me, not sure what race condition is happening, but i tested before sending to you and that's why i added e0dddc2 |
|
I saw that the icon doesn't update when I don't actually click reload on the extensions browser. So, maybe that was why it was harder to test. I think using a higher res icon should help. |
Oh, sorry, wrong issue - you can't repro the staging issue? Let me check what's up on my end then. |
|
Yeah, it seems to repro for me still. I can post any debug output if you want - let me know. From the debug panel, I see that it says: EDIT: sometimes it randomly goes to When it is false: It seems to just load nothing in the top panel. |
|
Fixed the logged issue. Was rare in my case but able to reproduce after multiple tries. Was not reproducible when happened in this order But when it some case (could be to the stack/queeu js runtime) Was causing that the latter succedded as user were still with it's cookie, but whenever it remember what url to use (in this case staging), was breaking for the staging url, meaning that indeed was authenticated but for the wrong environment. My fix is to make sure the authContext do any query after the storage is completly set from whatever is set in the chrome.local |
|
Nice, that fixes the issue for me - thanks! |
…-urls-change-page-break
|
@foxish ready for another pass |
|
Waiting for a response on #65 (comment) @davixcky - I want to try and see if there's a clearer way to set these auth and loading vars. I think we're separating the loading and authstate which is prone to bugs, and it might make more sense to create a single set of auth states that we track and derive when to set isLoading from that. |
Sgtm, i will do the latter |
|
@foxish done |
|
After the latest change, both staging and prod are not working for me just like before the fix you did in #65 (comment). It is authenticated, but shows just loading... |
|
@foxish i will revert my last commit and do it in a separate PR, agree? |
|
sgtm, that's ok with me - lmk once it's reverted, I'll review once again and then we can merge this. |
|
@foxish i think i was able to manage and fix the switch, LMK if that works to you. However i saw once issue that is when going from env to custom, the custom appears as blank but if you open and close, will appear correctly So looks like a state is hanging |
|
Works as expected! Checking the code |
|
@foxish i have to change a little bit the urls to add / cause the sanitize was appending "/" and that was partially causing the issue of not seeing anything at all too |
| export const PROD_SIGNADOT_PREVIEW_URL = "https://browser-extension-auth-redirect.preview.signadot.com"; | ||
| export const PROD_SIGNADOT_DASHBOARD_URL = "https://app.signadot.com"; | ||
| export const PROD_SIGNADOT_API_URL = "https://api.signadot.com"; | ||
| export const PROD_SIGNADOT_PREVIEW_URL = "https://browser-extension-auth-redirect.preview.signadot.com/"; |
There was a problem hiding this comment.
nit: the trailing slashes seem surprising to me - we'll forget to add it. I'd rather change the calling site to construct URLs safely. I don't feel too strongly about this however.
There was a problem hiding this comment.
Don't worries
Sanitize added automatically, but i have to added here also so we get the match in the toggles, otherwise if you select staging it will set to custom, because the missing /
src/contexts/AuthContext.tsx
Outdated
|
|
||
| type AuthState = | ||
| | { state: "loading"; user: undefined; org: undefined } | ||
| | { state: "not-authenticated"; user: undefined; org: undefined } |
| if (!settings.signadotUrls.apiUrl) { | ||
| throw new Error("API URL not configured"); | ||
| } | ||
| return fetchSandboxes(settings.signadotUrls.apiUrl, authState.org.name); |
There was a problem hiding this comment.
This is much nicer to not have invalid calls made, thanks for the fix.
src/contexts/AuthContext.tsx
Outdated
| } | ||
|
|
||
| type AuthState = | ||
| | { state: "loading"; user: undefined; org: undefined } |
There was a problem hiding this comment.
This field could be called "status" to avoid AuthState.state that reads weirdly.
sanitize shouldn't be appending anything based the examples they have here: https://github.com/braintree/sanitize-url - I'm surprised by that. |
|
@foxish suggestions applied |
|
@foxish PTAL |
|
I'm not happy about the trailing slashes in the URLs here: #65 (comment) - can you fix that instead and if |
|
I haven't see a similar library to sanitize, anyways we should keep in mind we are going to be the ones doing the custom urls |
foxish
left a comment
There was a problem hiding this comment.
LGTM, but please file a follow up issue to address the URLs



Issue:
The sessionn were expired and it was not reseting the cookies in case they were needed. Also internalstate was not being reset after change.
So i created a utlity function that resets to it's original state whenever there is a apiurl change