Skip to content

Commit

Permalink
fix: netlify identity registration link handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pmelab committed Jan 8, 2024
1 parent 7a6f5ee commit 4c2e948
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions apps/website/gatsby-ssr.ts → apps/website/gatsby-ssr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import './styles.css';

import { Locale, registerExecutor } from '@custom/schema';
import { GatsbySSR } from 'gatsby';
import React from 'react';

import { drupalExecutor } from './src/utils/drupal-executor';

export const onRenderBody: GatsbySSR['onRenderBody'] = ({
setHtmlAttributes,
setHeadComponents,
pathname,
}) => {
registerExecutor(drupalExecutor(`/graphql`));
Expand All @@ -27,4 +29,23 @@ export const onRenderBody: GatsbySSR['onRenderBody'] = ({
// We don't know the language.
}
}
// Remove this if Netlify identity is not used.
setHeadComponents([
<script
key="netlify-identity-widget"
src="https://identity.netlify.com/v1/netlify-identity-widget.js"
/>,
<script key="netlify-identity-redirect" dangerouslySetInnerHTML={{
__html: `
if (window.netlifyIdentity) {
window.netlifyIdentity.on("init", user => {
if (!user) {
window.netlifyIdentity.on("login", () => {
document.location.href = "/admin/";
});
}
});
}
`}} />
]);
};

0 comments on commit 4c2e948

Please sign in to comment.