-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
e033e75
to
bcc0dc5
Compare
dd3b769
to
445565d
Compare
There was a problem hiding this 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.
d1384c1
to
a5f94a5
Compare
9d25621
to
abebd8a
Compare
e013ba2
to
f98d29a
Compare
f98d29a
to
4a7b209
Compare
src/libs/functions/session.js
Outdated
} | ||
|
||
const fetchSessionCode = client => async () => | ||
(await client.getStackClient().fetchSessionCode()).session_code |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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)
src/libs/functions/session.js
Outdated
(await client.getStackClient().fetchSessionCode()).session_code | ||
|
||
const wrapUrl = client => async uri => | ||
appendParams(uri, strings.SESSION_CODE, await fetchSessionCode(client)()) |
There was a problem hiding this comment.
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? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
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
src/libs/functions/session.js
Outdated
|
||
export const handleCreateSession = client => uri => wrapUrl(client)(uri) | ||
|
||
export const shouldInterceptAuth = client => url => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same...
There was a problem hiding this comment.
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/libs/functions/session.js
Outdated
export const shouldInterceptAuth = client => url => | ||
url.includes(`${client.getStackClient().uri}${strings.authLogin}`) | ||
|
||
export const handleInterceptAuth = client => url => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same...
There was a problem hiding this comment.
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)
455ab56
to
a09e49a
Compare
a09e49a
to
62393d1
Compare
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 :/ |
(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