@@ -3,7 +3,7 @@ import { observer } from 'mobx-react';
3
3
import Error from 'next/error' ;
4
4
import Head from 'next/head' ;
5
5
import Router from 'next/router' ;
6
- import { NextPageContext } from 'next' ;
6
+ // import { NextPageContext } from 'next';
7
7
import React from 'react' ;
8
8
9
9
import LoginButton from '../components/common/LoginButton' ;
@@ -13,24 +13,23 @@ import { Team } from '../lib/store/team';
13
13
import { Store } from '../lib/store' ;
14
14
import withAuth from '../lib/withAuth' ;
15
15
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
+ }
18
22
19
- try {
20
- const { team } = await getTeamByTokenApiMethod ( token as string , context . req ) ;
23
+ try {
24
+ const { team } = await getTeamByTokenApiMethod ( token , ctx . req ) ;
21
25
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 { } ;
26
30
}
27
- } catch ( error ) {
28
- console . log ( error ) ;
29
- return { props : { } } ;
30
31
}
31
- }
32
32
33
- class InvitationPageComp extends React . Component < { store : Store ; team : Team ; token : string } > {
34
33
public render ( ) {
35
34
const { team, token, store } = this . props ;
36
35
@@ -73,7 +72,7 @@ class InvitationPageComp extends React.Component<{ store: Store; team: Team; tok
73
72
) ;
74
73
}
75
74
76
- public componentDidMount ( ) {
75
+ public async componentDidMount ( ) {
77
76
const { store, team, token } = this . props ;
78
77
79
78
const user = store . currentUser ;
@@ -87,4 +86,23 @@ class InvitationPageComp extends React.Component<{ store: Store; team: Team; tok
87
86
}
88
87
}
89
88
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
+
90
108
export default withAuth ( observer ( InvitationPageComp ) , { loginRequired : false } ) ;
0 commit comments