Skip to content

Commit 8609d23

Browse files
committed
remove getServerSideProps from invitation.tsx #193
1 parent 0983256 commit 8609d23

File tree

9 files changed

+285
-155
lines changed

9 files changed

+285
-155
lines changed

book/10-begin/app/pages/invitation.tsx

+33-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { observer } from 'mobx-react';
33
import Error from 'next/error';
44
import Head from 'next/head';
55
import Router from 'next/router';
6-
import { NextPageContext } from 'next';
6+
// import { NextPageContext } from 'next';
77
import React from 'react';
88

99
import LoginButton from '../components/common/LoginButton';
@@ -13,24 +13,23 @@ import { Team } from '../lib/store/team';
1313
import { Store } from '../lib/store';
1414
import withAuth from '../lib/withAuth';
1515

16-
export async function getServerSideProps(context: NextPageContext) {
17-
const { token } = context.query;
16+
class InvitationPageComp extends React.Component<{ store: Store; team: Team; token: string }> {
17+
public static async getInitialProps(ctx) {
18+
const { token } = ctx.query;
19+
if (!token) {
20+
return {};
21+
}
1822

19-
try {
20-
const { team } = await getTeamByTokenApiMethod(token as string, context.req);
23+
try {
24+
const { team } = await getTeamByTokenApiMethod(token, ctx.req);
2125

22-
if (team && token) {
23-
return { props: { team, token } };
24-
} else {
25-
return { props: {} };
26+
return { team, token };
27+
} catch (error) {
28+
console.log(error);
29+
return {};
2630
}
27-
} catch (error) {
28-
console.log(error);
29-
return { props: {} };
3031
}
31-
}
3232

33-
class InvitationPageComp extends React.Component<{ store: Store; team: Team; token: string }> {
3433
public render() {
3534
const { team, token, store } = this.props;
3635

@@ -73,7 +72,7 @@ class InvitationPageComp extends React.Component<{ store: Store; team: Team; tok
7372
);
7473
}
7574

76-
public componentDidMount() {
75+
public async componentDidMount() {
7776
const { store, team, token } = this.props;
7877

7978
const user = store.currentUser;
@@ -87,4 +86,23 @@ class InvitationPageComp extends React.Component<{ store: Store; team: Team; tok
8786
}
8887
}
8988

89+
// export async function getServerSideProps(context: NextPageContext) {
90+
// const { token } = context.query;
91+
92+
// try {
93+
// const { team } = await getTeamByTokenApiMethod(token as string, context.req);
94+
95+
// if (team && token) {
96+
// return { props: { team, token } };
97+
// } else {
98+
// return { props: {} };
99+
// }
100+
// } catch (error) {
101+
// console.log(error);
102+
// return { props: {} };
103+
// }
104+
// }
105+
106+
// see our explanation for not using getServerSideProps at this time: https://github.com/async-labs/saas/issues/193
107+
90108
export default withAuth(observer(InvitationPageComp), { loginRequired: false });

book/10-end-functional/app/pages/invitation.tsx

+27-25
Original file line numberDiff line numberDiff line change
@@ -86,38 +86,40 @@ function InvitationPageComp({ store, isMobile, firstGridItem, teamRequired, team
8686
);
8787
}
8888

89-
// InvitationPageComp.getInitialProps = async (ctx: NextPageContext) => {
90-
// const { token } = ctx.query;
89+
InvitationPageComp.getInitialProps = async (ctx: NextPageContext) => {
90+
const { token } = ctx.query;
9191

92-
// if (!token) {
93-
// return {};
94-
// }
92+
if (!token) {
93+
return {};
94+
}
95+
96+
try {
97+
const { team } = await getTeamByTokenApiMethod(token as string, ctx.req);
98+
99+
return { team, token };
100+
} catch (error) {
101+
console.log(error);
102+
return {};
103+
}
104+
};
105+
106+
// export async function getServerSideProps(context: NextPageContext) {
107+
// const { token } = context.query;
95108

96109
// try {
97-
// const { team } = await getTeamByTokenApiMethod(token as string, ctx.req);
110+
// const { team } = await getTeamByTokenApiMethod(token as string, context.req);
98111

99-
// return { team, token };
112+
// if (team && token) {
113+
// return { props: { team, token } };
114+
// } else {
115+
// return { props: {} };
116+
// }
100117
// } catch (error) {
101118
// console.log(error);
102-
// return {};
119+
// return { props: {} };
103120
// }
104-
// };
105-
106-
export async function getServerSideProps(context: NextPageContext) {
107-
const { token } = context.query;
121+
// }
108122

109-
try {
110-
const { team } = await getTeamByTokenApiMethod(token as string, context.req);
111-
112-
if (team && token) {
113-
return { props: { team, token } };
114-
} else {
115-
return { props: {} };
116-
}
117-
} catch (error) {
118-
console.log(error);
119-
return { props: {} };
120-
}
121-
}
123+
// see our explanation for not using getServerSideProps at this time: https://github.com/async-labs/saas/issues/193
122124

123125
export default withAuth(observer(InvitationPageComp), { loginRequired: false });

book/10-end/app/pages/invitation.tsx

+33-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { observer } from 'mobx-react';
33
import Error from 'next/error';
44
import Head from 'next/head';
55
import Router from 'next/router';
6-
import { NextPageContext } from 'next';
6+
// import { NextPageContext } from 'next';
77
import React from 'react';
88

99
import LoginButton from '../components/common/LoginButton';
@@ -15,24 +15,23 @@ import withAuth from '../lib/withAuth';
1515

1616
const dev = process.env.NODE_ENV !== 'production';
1717

18-
export async function getServerSideProps(context: NextPageContext) {
19-
const { token } = context.query;
18+
class InvitationPageComp extends React.Component<{ store: Store; team: Team; token: string }> {
19+
public static async getInitialProps(ctx) {
20+
const { token } = ctx.query;
21+
if (!token) {
22+
return {};
23+
}
2024

21-
try {
22-
const { team } = await getTeamByTokenApiMethod(token as string, context.req);
25+
try {
26+
const { team } = await getTeamByTokenApiMethod(token, ctx.req);
2327

24-
if (team && token) {
25-
return { props: { team, token } };
26-
} else {
27-
return { props: {} };
28+
return { team, token };
29+
} catch (error) {
30+
console.log(error);
31+
return {};
2832
}
29-
} catch (error) {
30-
console.log(error);
31-
return { props: {} };
3233
}
33-
}
3434

35-
class InvitationPageComp extends React.Component<{ store: Store; team: Team; token: string }> {
3635
public render() {
3736
const { team, token, store } = this.props;
3837

@@ -75,7 +74,7 @@ class InvitationPageComp extends React.Component<{ store: Store; team: Team; tok
7574
);
7675
}
7776

78-
public componentDidMount() {
77+
public async componentDidMount() {
7978
const { store, team, token } = this.props;
8079

8180
const user = store.currentUser;
@@ -93,4 +92,23 @@ class InvitationPageComp extends React.Component<{ store: Store; team: Team; tok
9392
}
9493
}
9594

95+
// export async function getServerSideProps(context: NextPageContext) {
96+
// const { token } = context.query;
97+
98+
// try {
99+
// const { team } = await getTeamByTokenApiMethod(token as string, context.req);
100+
101+
// if (team && token) {
102+
// return { props: { team, token } };
103+
// } else {
104+
// return { props: {} };
105+
// }
106+
// } catch (error) {
107+
// console.log(error);
108+
// return { props: {} };
109+
// }
110+
// }
111+
112+
// see our explanation for not using getServerSideProps at this time: https://github.com/async-labs/saas/issues/193
113+
96114
export default withAuth(observer(InvitationPageComp), { loginRequired: false });

book/7-end/app/pages/invitation.tsx

+33-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { observer } from 'mobx-react';
33
import Error from 'next/error';
44
import Head from 'next/head';
55
import Router from 'next/router';
6-
import { NextPageContext } from 'next';
6+
// import { NextPageContext } from 'next';
77
import React from 'react';
88

99
import LoginButton from '../components/common/LoginButton';
@@ -13,24 +13,23 @@ import { Team } from '../lib/store/team';
1313
import { Store } from '../lib/store';
1414
import withAuth from '../lib/withAuth';
1515

16-
export async function getServerSideProps(context: NextPageContext) {
17-
const { token } = context.query;
16+
class InvitationPageComp extends React.Component<{ store: Store; team: Team; token: string }> {
17+
public static async getInitialProps(ctx) {
18+
const { token } = ctx.query;
19+
if (!token) {
20+
return {};
21+
}
1822

19-
try {
20-
const { team } = await getTeamByTokenApiMethod(token as string, context.req);
23+
try {
24+
const { team } = await getTeamByTokenApiMethod(token, ctx.req);
2125

22-
if (team && token) {
23-
return { props: { team, token } };
24-
} else {
25-
return { props: {} };
26+
return { team, token };
27+
} catch (error) {
28+
console.log(error);
29+
return {};
2630
}
27-
} catch (error) {
28-
console.log(error);
29-
return { props: {} };
3031
}
31-
}
3232

33-
class InvitationPageComp extends React.Component<{ store: Store; team: Team; token: string }> {
3433
public render() {
3534
const { team, token, store } = this.props;
3635

@@ -73,7 +72,7 @@ class InvitationPageComp extends React.Component<{ store: Store; team: Team; tok
7372
);
7473
}
7574

76-
public componentDidMount() {
75+
public async componentDidMount() {
7776
const { store, team, token } = this.props;
7877

7978
const user = store.currentUser;
@@ -87,4 +86,23 @@ class InvitationPageComp extends React.Component<{ store: Store; team: Team; tok
8786
}
8887
}
8988

89+
// export async function getServerSideProps(context: NextPageContext) {
90+
// const { token } = context.query;
91+
92+
// try {
93+
// const { team } = await getTeamByTokenApiMethod(token as string, context.req);
94+
95+
// if (team && token) {
96+
// return { props: { team, token } };
97+
// } else {
98+
// return { props: {} };
99+
// }
100+
// } catch (error) {
101+
// console.log(error);
102+
// return { props: {} };
103+
// }
104+
// }
105+
106+
// see our explanation for not using getServerSideProps at this time: https://github.com/async-labs/saas/issues/193
107+
90108
export default withAuth(observer(InvitationPageComp), { loginRequired: false });

book/8-begin/app/pages/invitation.tsx

+33-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { observer } from 'mobx-react';
33
import Error from 'next/error';
44
import Head from 'next/head';
55
import Router from 'next/router';
6-
import { NextPageContext } from 'next';
6+
// import { NextPageContext } from 'next';
77
import React from 'react';
88

99
import LoginButton from '../components/common/LoginButton';
@@ -13,24 +13,23 @@ import { Team } from '../lib/store/team';
1313
import { Store } from '../lib/store';
1414
import withAuth from '../lib/withAuth';
1515

16-
export async function getServerSideProps(context: NextPageContext) {
17-
const { token } = context.query;
16+
class InvitationPageComp extends React.Component<{ store: Store; team: Team; token: string }> {
17+
public static async getInitialProps(ctx) {
18+
const { token } = ctx.query;
19+
if (!token) {
20+
return {};
21+
}
1822

19-
try {
20-
const { team } = await getTeamByTokenApiMethod(token as string, context.req);
23+
try {
24+
const { team } = await getTeamByTokenApiMethod(token, ctx.req);
2125

22-
if (team && token) {
23-
return { props: { team, token } };
24-
} else {
25-
return { props: {} };
26+
return { team, token };
27+
} catch (error) {
28+
console.log(error);
29+
return {};
2630
}
27-
} catch (error) {
28-
console.log(error);
29-
return { props: {} };
3031
}
31-
}
3232

33-
class InvitationPageComp extends React.Component<{ store: Store; team: Team; token: string }> {
3433
public render() {
3534
const { team, token, store } = this.props;
3635

@@ -73,7 +72,7 @@ class InvitationPageComp extends React.Component<{ store: Store; team: Team; tok
7372
);
7473
}
7574

76-
public componentDidMount() {
75+
public async componentDidMount() {
7776
const { store, team, token } = this.props;
7877

7978
const user = store.currentUser;
@@ -87,4 +86,23 @@ class InvitationPageComp extends React.Component<{ store: Store; team: Team; tok
8786
}
8887
}
8988

89+
// export async function getServerSideProps(context: NextPageContext) {
90+
// const { token } = context.query;
91+
92+
// try {
93+
// const { team } = await getTeamByTokenApiMethod(token as string, context.req);
94+
95+
// if (team && token) {
96+
// return { props: { team, token } };
97+
// } else {
98+
// return { props: {} };
99+
// }
100+
// } catch (error) {
101+
// console.log(error);
102+
// return { props: {} };
103+
// }
104+
// }
105+
106+
// see our explanation for not using getServerSideProps at this time: https://github.com/async-labs/saas/issues/193
107+
90108
export default withAuth(observer(InvitationPageComp), { loginRequired: false });

0 commit comments

Comments
 (0)