-
Notifications
You must be signed in to change notification settings - Fork 218
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
Notion Ask to Login after tapping Back button #237
Comments
+1 |
+1 |
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
Notably, when checking sites in the Fruition-users 'Showcase' https://stephenou.notion.site/92053970e5084019ac096d2df7e7f440?v=2bed11f9a95d41f59e8af11a7746c339, even if the page content is displaying, it's coming back as an HTTP 404 error (prompting some browsers to display an extra error-banner), and navigating forward to subpages works, but backing-up lands on the Notion sign-up page. |
I resolved the issue!! Please try and see if this resolves it for you. Chrome Dev Tools Console was displaying the following error messages:
To Solve:
|
hi @eeshabarua , do not get to work it. Replaced the part with yours and of course changed eeshabarua.... But not working. |
@jruers Hmm... can you describe the behavior? Is the back button still prompting reauth? |
Maybe I replace something wrong, but the notion site is not found after I adjusted the worker... |
I apologize, the code block I provided still had Here is my full
|
@eeshabarua tried your worker... still prompting reauth |
After implementing this fix for another issue for fruition, my issue here seems to also have resolved itself. |
Worked for me, thanks Eesha! |
Dark/light fix also worked for me. The earlier one forwarded to my actual notion URL instead of my vanity URL so no-go there. |
@gojomo @jevanjovandy Currently the source code is outdated, it will have to be updated, I have a functional one that I will publish soon. (maybe in the pull or in this section) the errors are as mentioned ca Domain changes, script, cloudflare worker . |
Thanks for sharing your fix, @eeshabarua! It did sort out the problem for me, though it seems that when I change the code it also messes up my 'pretty' URLs, which start displaying as *****.notion.site
It's so lucky you tried this fix already, @JustSleightly, thanks for sharing! This dark/light mode code change actually somehow did fix the back-login problem for me too. Appreciate this community! |
@olimpa Any update on your update? :D The dark/light fix worked for me, but I don't like the reloading part. EDIT: I've just tested the dark/light solution without |
I was using the previous code wrong but it isn't working. // CONFIGURATION STARTS HERE
// Step 1: enter your domain name like fruitionsite.com
const MY_DOMAIN = 'codinghelp.site';
/*
* Step 2: enter your URL slug to page ID mapping
* The key on the left is the slug (without the slash)
* The value on the right is the Notion page ID
*/
const SLUG_TO_PAGE = {
'': '4c97396d18034520bf450b7d7485a4c4?pvs=4',
};
// CONFIGURATION ENDS HERE
const PAGE_TO_SLUG = {};
const slugs = [];
const pages = [];
Object.keys(SLUG_TO_PAGE).forEach(slug => {
const page = SLUG_TO_PAGE[slug];
slugs.push(slug);
pages.push(page);
PAGE_TO_SLUG[page] = slug;
});
addEventListener('fetch', event => {
event.respondWith(fetchAndApply(event.request));
});
function generateSitemap() {
let sitemap = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
slugs.forEach(
(slug) =>
(sitemap +=
'<url><loc>https://' + MY_DOMAIN + '/' + slug + '</loc></url>')
);
sitemap += '</urlset>';
return sitemap;
}
const corsHeaders = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, HEAD, POST, PUT, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type',
};
function handleOptions(request) {
if (request.headers.get('Origin') !== null &&
request.headers.get('Access-Control-Request-Method') !== null &&
request.headers.get('Access-Control-Request-Headers') !== null) {
// Handle CORS pre-flight request.
return new Response(null, {
headers: corsHeaders
});
} else {
// Handle standard OPTIONS request.
return new Response(null, {
headers: {
'Allow': 'GET, HEAD, POST, PUT, OPTIONS',
}
});
}
}
async function fetchAndApply(request) {
if (request.method === 'OPTIONS') {
return handleOptions(request);
}
let url = new URL(request.url);
url.hostname = 'dudethatserin.notion.site';
if (url.pathname === '/robots.txt') {
return new Response('Sitemap: https://' + MY_DOMAIN + '/sitemap.xml');
}
if (url.pathname === '/sitemap.xml') {
let response = new Response(generateSitemap());
response.headers.set('content-type', 'application/xml');
return response;
}
let response;
if (url.pathname.startsWith('/app') && url.pathname.endsWith('js')) {
response = await fetch(url.toString());
let body = await response.text();
response = new Response(body.replace(/dudethatserin.notion.site/g, MY_DOMAIN).replace(/notion.so/g, MY_DOMAIN), response);
response.headers.set('Content-Type', 'application/x-javascript');
return response;
} else if ((url.pathname.startsWith('/api'))) {
// Forward API
response = await fetch(url.toString(), {
body: url.pathname.startsWith('/api/v3/getPublicPageData') ? null : request.body,
headers: {
'content-type': 'application/json;charset=UTF-8',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36'
},
method: 'POST',
});
response = new Response(response.body, response);
response.headers.set('Access-Control-Allow-Origin', '*');
return response;
} else {
const currentSlug = url.pathname.slice(1);
const pageId = SLUG_TO_PAGE[currentSlug];
if (pageId) {
const notionUrl = `https://dudethatserin.notion.site/${pageId.replace(/-/g, '')}`;
return Response.redirect(notionUrl, 301);
}
response = await fetch(url.toString(), {
body: request.body,
headers: request.headers,
method: request.method,
});
response = new Response(response.body, response);
response.headers.delete('Content-Security-Policy');
response.headers.delete('X-Content-Security-Policy');
// Soft navigation handling
if (slugs.indexOf(currentSlug) > -1) {
const destinationPageId = SLUG_TO_PAGE[currentSlug];
if (destinationPageId) {
const notionUrl = `https://dudethatserin.notion.site/${destinationPageId.replace(/-/g, '')}`;
const { pathname, search, hash } = new URL(notionUrl);
const redirectUrl = `${MY_DOMAIN}/${currentSlug}${search}${hash}`;
response.headers.set('Content-Type', 'text/html');
response.headers.set('Cache-Control', 'no-store');
response.headers.set('Location', redirectUrl);
response.status = 302;
return response;
}
}
return appendJavascript(response, SLUG_TO_PAGE);
}
}
class MetaRewriter {
element(element) {
// Modify meta tags for SEO if needed
}
}
class HeadRewriter {
element(element) {
// Modify head content if needed, e.g., adding custom styles, scripts, or fonts
}
}
class BodyRewriter {
constructor(SLUG_TO_PAGE) {
this.SLUG_TO_PAGE = SLUG_TO_PAGE;
}
element(element) {
// Modify body content if needed
}
}
async function appendJavascript(res, SLUG_TO_PAGE) {
return new HTMLRewriter()
.on('title', new MetaRewriter())
.on('meta', new MetaRewriter())
.on('head', new HeadRewriter())
.on('body', new BodyRewriter(SLUG_TO_PAGE))
.transform(res);
} |
My website is imamhanafi.com , I have used the script above but it is not working. can anyone help why? |
I seem to have resolved the issue of requesting login after clicking the back button. // const open = window.XMLHttpRequest.prototype.open;
// window.XMLHttpRequest.prototype.open = function() {
// arguments[1] = arguments[1].replace('${MY_DOMAIN}', 'www.notion.so');
// return open.apply(this, [].slice.call(arguments));
// }; good luck 🎉 |
|
Has anyone had any luck with this? I haven't figured out how to prevent the Notion login on using the back button. I'm using https://github.com/velsa/notehost, so the login just flashes for a moment and then correctly redirects, but this behavior isn't ideal. |
I tried @eeshabarua 's fix and @blankbro 's fix and the dark/light fix. None of them worked for me. I found a new fix: replace this line (also mentioned at #264 (comment)) also cc @DudeThatsErin I saw that your appseeker site is still has the issue, do you want to give it a try? |
@knownissuewontfix - that worked for me. @DudeThatsErin: I'm using notehost and I edited index.cjs to match this suggestion. I'm not very good with Github but I can submit a PR for notehost if you can provide some guidance. |
I'm not a maintainer so I can't approve it but this is how: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request |
Notion asking to Login after Back button tapped.
I think this comes from Notion changing 'www.notion.so' to 'yoursite.notion.site'.
Anyone already have a solution to this problem? Thanks before.
The text was updated successfully, but these errors were encountered: