Skip to content

Commit

Permalink
fix: Reapply home cookie on focus
Browse files Browse the repository at this point in the history
  • Loading branch information
acezard authored and Crash-- committed Jun 10, 2022
1 parent 6701fbe commit 2b92e64
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/libs/httpserver/httpCookieManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const parseCookie = cookieString => {
}
}

export let setHomeCookie

/**
* Set the cookie into the device by using CookieManager
*
Expand All @@ -72,7 +74,7 @@ const parseCookie = cookieString => {
* @param {CozyClient} client - CozyClient instance
* @returns {Promise<boolean>}
*/
export const setCookie = async (cookieString, client) => {
export const setCookie = async (cookieString, client, slug) => {
const cookie = parseCookie(cookieString)

const appUrl = client.getStackClient().uri
Expand All @@ -89,5 +91,9 @@ export const setCookie = async (cookieString, client) => {
sameSite: 'None' // This must be force to 'None' so iOS accepts to send it through "html injected" webview
}

if (slug === 'home') {
setHomeCookie = () => CookieManager.set(appUrl, stackCookie, true)
}

return CookieManager.set(appUrl, stackCookie, true)
}
2 changes: 1 addition & 1 deletion src/libs/httpserver/httpServerProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const HttpServerProvider = props => {

const { cookie, templateValues } = await fetchAppDataForSlug(slug, client)

await setCookie(cookie, client)
await setCookie(cookie, client, slug)
const rawHtml = await getIndexForFqdnAndSlug(fqdn, slug)

if (!rawHtml) {
Expand Down
3 changes: 3 additions & 0 deletions src/screens/home/components/HomeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { consumeRouteParameter } from '/libs/functions/routeHelpers'
import { resetUIState } from '/libs/intents/setFlagshipUI'
import { statusBarHeight, getNavbarHeight } from '/libs/dimensions'
import { useSession } from '/hooks/useSession'
import { setHomeCookie } from '/libs/httpserver/httpCookieManager'

const injectedJavaScriptBeforeContentLoaded = () => `
window.addEventListener('load', (event) => {
Expand Down Expand Up @@ -36,6 +37,8 @@ const HomeView = ({ route, navigation, setLauncherContext }) => {
const unsubscribe = navigation.addListener('focus', () => {
nativeIntent?.call(uri, 'closeApp')

setHomeCookie?.()

if (uri) {
const konnectorParam = consumeRouteParameter(
'konnector',
Expand Down

0 comments on commit 2b92e64

Please sign in to comment.