Skip to content

Commit

Permalink
Merge pull request #9653 from weseek/fix/160681-161831-redirect-after…
Browse files Browse the repository at this point in the history
…-login

fix: Redirection after login does not work on systems with guest mode enabled
  • Loading branch information
mergify[bot] authored Feb 20, 2025
2 parents 2522823 + 5bf1866 commit 2030c87
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions apps/app/src/pages/login/index.page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';

import { pagePathUtils } from '@growi/core/dist/utils';
import type {
NextPage, GetServerSideProps, GetServerSidePropsContext,
} from 'next';
Expand All @@ -24,6 +25,8 @@ import {
import styles from './index.module.scss';


const { isPermalink, isUserPage, isUsersTopPage } = pagePathUtils;

const LoginForm = dynamic(() => import('~/client/components/LoginForm').then(mod => mod.LoginForm), { ssr: false });


Expand Down Expand Up @@ -127,6 +130,15 @@ async function injectServerConfigurations(context: GetServerSidePropsContext, pr
export const getServerSideProps: GetServerSideProps = async(context: GetServerSidePropsContext) => {
const result = await getServerSideCommonProps(context);


// redirect to the page the user was on before moving to the Login Page
if (context.req.headers.referer != null) {
const urlBeforeLogin = new URL(context.req.headers.referer);
if (isPermalink(urlBeforeLogin.pathname) || isUserPage(urlBeforeLogin.pathname) || isUsersTopPage(urlBeforeLogin.pathname)) {
(context.req as CrowiRequest).session.redirectTo = urlBeforeLogin.href;
}
}

// check for presence
// see: https://github.com/vercel/next.js/issues/19271#issuecomment-730006862
if (!('props' in result)) {
Expand Down

0 comments on commit 2030c87

Please sign in to comment.