Skip to content
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

fix: An error occurred during user activation via email #8767

Merged
merged 5 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/app/src/components/CompleteUserRegistrationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const CompleteUserRegistrationForm: React.FC<Props> = (props: Props) => {

<div className="input-group justify-content-center mt-4">
<button
type="button"
type="submit"
disabled={forceDisableForm || disableForm}
className="btn btn-secondary btn-register col-6 mx-auto d-flex"
>
Expand Down
16 changes: 8 additions & 8 deletions apps/app/src/pages/user-activation.page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextPage, GetServerSideProps, GetServerSidePropsContext } from 'next';
import type { NextPage, GetServerSideProps, GetServerSidePropsContext } from 'next';
import { useTranslation } from 'next-i18next';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import Head from 'next/head';
Expand All @@ -8,10 +8,12 @@ import { NoLoginLayout } from '~/components/Layout/NoLoginLayout';
import type { CrowiRequest } from '~/interfaces/crowi-request';
import type { UserActivationErrorCode } from '~/interfaces/errors/user-activation';
import type { RegistrationMode } from '~/interfaces/registration-mode';
import { IUserRegistrationOrder } from '~/server/models/user-registration-order';
import type { IUserRegistrationOrder } from '~/server/models/user-registration-order';
import type { CrowiReq } from '~/server/routes/user-activation';

import type { CommonProps } from './utils/commons';
import {
getServerSideCommonProps, getNextI18NextConfig, generateCustomTitle, CommonProps,
getServerSideCommonProps, getNextI18NextConfig, generateCustomTitle,
} from './utils/commons';

type Props = CommonProps & {
Expand Down Expand Up @@ -56,26 +58,24 @@ async function injectNextI18NextConfigurations(context: GetServerSidePropsContex

export const getServerSideProps: GetServerSideProps = async(context: GetServerSidePropsContext) => {
const result = await getServerSideCommonProps(context);
const req: CrowiRequest = context.req as CrowiRequest;
const req: CrowiReq & CrowiRequest = context.req as CrowiReq & CrowiRequest;

miya marked this conversation as resolved.
Show resolved Hide resolved
// check for presence
// see: https://github.com/vercel/next.js/issues/19271#issuecomment-730006862
if (!('props' in result)) {
throw new Error('invalid getSSP result');
}

const props: Props = result.props as Props;

if (context.query.userRegistrationOrder != null) {
const userRegistrationOrder = context.query.userRegistrationOrder as unknown as IUserRegistrationOrder;
if (req.userRegistrationOrder != null) {
const userRegistrationOrder = req.userRegistrationOrder as unknown as IUserRegistrationOrder;
props.email = userRegistrationOrder.email;
miya marked this conversation as resolved.
Show resolved Hide resolved
props.token = userRegistrationOrder.token;
}

if (typeof context.query.errorCode === 'string') {
props.errorCode = context.query.errorCode as UserActivationErrorCode;
}

props.registrationMode = req.crowi.configManager.getConfig('crowi', 'security:registrationMode');
props.isEmailAuthenticationEnabled = req.crowi.configManager.getConfig('crowi', 'security:passport-local:isEmailAuthenticationEnabled');

Expand Down
6 changes: 3 additions & 3 deletions apps/app/src/server/routes/user-activation.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Response, NextFunction } from 'express';
import type { Response, NextFunction } from 'express';

import type { UserActivationErrorCode } from '~/interfaces/errors/user-activation';
import { ReqWithUserRegistrationOrder } from '~/server/middlewares/inject-user-registration-order-by-token-middleware';
import type { ReqWithUserRegistrationOrder } from '~/server/middlewares/inject-user-registration-order-by-token-middleware';

type Crowi = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
nextApp: any,
}

type CrowiReq = ReqWithUserRegistrationOrder & {
export type CrowiReq = ReqWithUserRegistrationOrder & {
crowi: Crowi,
miya marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
Loading