Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement session code management #64

Merged
merged 5 commits into from
Jan 27, 2022

Conversation

acezard
Copy link
Contributor

@acezard acezard commented Jan 11, 2022

(https://trello.com/c/7CaHns1b/86-%F0%9F%9A%80%F0%9F%97%9D%EF%B8%8F-e8-ne-pas-avoir-%C3%A0-se-reconnecter-lorsque-jacc%C3%A8de-aux-apps-2-3jh)

Problem: double authentication (manager/webview)

Solution: inject sessionCode token queried from the native app into the webview. Handle persistent data on wether the token was already injected or not in order to speed up first load

@acezard acezard force-pushed the feat--Implement-session-code-management branch from e033e75 to bcc0dc5 Compare January 13, 2022 13:24
@acezard acezard force-pushed the feat--Implement-session-code-management branch 2 times, most recently from dd3b769 to 445565d Compare January 17, 2022 16:13
Copy link
Contributor

@Crash-- Crash-- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is too complicated for what it has to do.

I don't understand the need of having a SessionService class.

@acezard acezard force-pushed the feat--Implement-session-code-management branch 6 times, most recently from d1384c1 to a5f94a5 Compare January 19, 2022 07:37
@acezard acezard changed the title WIP: Implement session code management feat: Implement session code management Jan 19, 2022
@acezard acezard requested a review from Crash-- January 19, 2022 07:39
.eslintrc.js Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
src/App.js Outdated Show resolved Hide resolved
@acezard acezard requested a review from Crash-- January 19, 2022 07:47
@acezard acezard force-pushed the feat--Implement-session-code-management branch 2 times, most recently from 9d25621 to abebd8a Compare January 19, 2022 08:21
src/libs/functions/session.js Outdated Show resolved Hide resolved
src/libs/functions/session.js Show resolved Hide resolved
src/strings.json Outdated Show resolved Hide resolved
@acezard acezard requested a review from Ldoppea January 24, 2022 14:25
@acezard acezard force-pushed the feat--Implement-session-code-management branch from e013ba2 to f98d29a Compare January 24, 2022 15:08
@acezard acezard force-pushed the feat--Implement-session-code-management branch from f98d29a to 4a7b209 Compare January 24, 2022 15:31
}

const fetchSessionCode = client => async () =>
(await client.getStackClient().fetchSessionCode()).session_code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const fetchSessionCode = async client => {
const { session_code } = await client.getStackClient().fetchSessionCode()
return session_code
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the higher order part #64 (comment)

(await client.getStackClient().fetchSessionCode()).session_code

const wrapUrl = client => async uri =>
appendParams(uri, strings.SESSION_CODE, await fetchSessionCode(client)())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here I don't understand the need of having function()(first)(second). Why no wrapUrl(client, uri) directly? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/cozy/cozy-react-native/pull/64/files#diff-814fc83774159036bb3be8ed60dbabbd330b5ccc31b70a7b294e7113502d3dfdR1

It seemed simpler to use higher-order functions here, so we can get the client instance in a react hook and still have decoupled functions easy to test outside of react env

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored a bit so now only 3 functions are HOF and I have one more as a function factory to simplify usage


export const handleCreateSession = client => uri => wrapUrl(client)(uri)

export const shouldInterceptAuth = client => url =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refer to #64 (comment) and #64 (comment)

export const shouldInterceptAuth = client => url =>
url.includes(`${client.getStackClient().uri}${strings.authLogin}`)

export const handleInterceptAuth = client => url =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refer to #64 (comment) and #64 (comment)

src/hooks/useSession.js Outdated Show resolved Hide resolved
@acezard acezard requested a review from Crash-- January 25, 2022 06:51
@acezard acezard force-pushed the feat--Implement-session-code-management branch from 455ab56 to a09e49a Compare January 25, 2022 06:58
@acezard acezard force-pushed the feat--Implement-session-code-management branch from a09e49a to 62393d1 Compare January 25, 2022 09:11
@Ldoppea
Copy link
Member

Ldoppea commented Jan 26, 2022

Did you see this PR ? cozy/cozy-client#1106

It doesn't do exactly what you need, but the code extracts the cozy's domain from any complex url and also a lot of test cases are described in unit tests. I recommend you to check the PR to verify if there are some edge cases that we missed, or maybe if some code may be reused in your "check if same domain" implementation.

@acezard
Copy link
Contributor Author

acezard commented Jan 27, 2022

Did you see this PR ? cozy/cozy-client#1106

It doesn't do exactly what you need, but the code extracts the cozy's domain from any complex url and also a lot of test cases are described in unit tests. I recommend you to check the PR to verify if there are some edge cases that we missed, or maybe if some code may be reused in your "check if same domain" implementation.

I didn't see it. I suggest to use this later (I add it as an issue). This current PR has been going for far too long :/

@acezard acezard merged commit 5f8c171 into master Jan 27, 2022
@acezard acezard deleted the feat--Implement-session-code-management branch January 27, 2022 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants