@@ -12,12 +12,18 @@ console.info(
12
12
13
13
type SignInStatus = 'checking' | 'signed-in' | 'signed-out' ;
14
14
15
+ type ProjectParams = {
16
+ projectId : string ;
17
+ csrfToken : string ;
18
+ csrfTime : string ;
19
+ } ;
20
+
15
21
type AtlasLoginReturnValue =
16
22
| {
17
23
status : 'checking' | 'signed-out' ;
18
- projectId : null ;
24
+ projectParams : null ;
19
25
}
20
- | { status : 'signed-in' ; projectId : string } ;
26
+ | { status : 'signed-in' ; projectParams : ProjectParams } ;
21
27
22
28
const bodyContainerStyles = css ( {
23
29
display : 'flex' ,
@@ -64,7 +70,9 @@ const IS_CI =
64
70
65
71
export function useAtlasProxySignIn ( ) : AtlasLoginReturnValue {
66
72
const [ status , setStatus ] = useState < SignInStatus > ( 'checking' ) ;
67
- const [ projectId , setProjectId ] = useState < string | null > ( null ) ;
73
+ const [ projectParams , setProjectParams ] = useState < ProjectParams | null > (
74
+ null
75
+ ) ;
68
76
69
77
const signIn = ( ( window as any ) . __signIn = useCallback ( async ( ) => {
70
78
try {
@@ -104,7 +112,12 @@ export function useAtlasProxySignIn(): AtlasLoginReturnValue {
104
112
if ( ! projectId ) {
105
113
throw new Error ( 'failed to get projectId' ) ;
106
114
}
107
- setProjectId ( projectId ) ;
115
+ const { csrfToken, csrfTime } = await fetch (
116
+ `/cloud-mongodb-com/v2/${ projectId } /params`
117
+ ) . then ( ( res ) => {
118
+ return res . json ( ) ;
119
+ } ) ;
120
+ setProjectParams ( { projectId, csrfToken, csrfTime } ) ;
108
121
setStatus ( 'signed-in' ) ;
109
122
if ( IS_CI ) {
110
123
return ;
@@ -151,12 +164,12 @@ export function useAtlasProxySignIn(): AtlasLoginReturnValue {
151
164
if ( status === 'checking' || status === 'signed-out' ) {
152
165
return {
153
166
status,
154
- projectId : null ,
167
+ projectParams : null ,
155
168
} ;
156
169
}
157
170
158
- if ( status === 'signed-in' && projectId ) {
159
- return { status, projectId } ;
171
+ if ( status === 'signed-in' && projectParams ) {
172
+ return { status, projectParams } ;
160
173
}
161
174
162
175
throw new Error ( 'Weird state, ask for help in Compass dev channel' ) ;
0 commit comments