|
1 | 1 | import*asCRfrom'typings'
|
| 2 | +import*asGfrom'typings/graphql' |
2 | 3 | importclientfrom'../../apollo'
|
3 | 4 | importauthenticateMutationfrom'../../apollo/mutations/authenticate'
|
4 | 5 | import{setAuthToken}from'../../apollo/auth'
|
5 | 6 | importchannelfrom'../../../services/channel'
|
6 | 7 |
|
| 8 | +interfaceAuthenticateData{ |
| 9 | +editorLogin:{ |
| 10 | +token:string |
| 11 | +user:G.User |
| 12 | +} |
| 13 | +} |
| 14 | + |
| 15 | +interfaceAuthenticateVariables{ |
| 16 | +machineId:string |
| 17 | +sessionId:string |
| 18 | +editor:'VSCODE' |
| 19 | +} |
| 20 | + |
7 | 21 | exportdefault{
|
8 | 22 | authenticate:(async(context:CR.MachineContext):Promise<void>=>{
|
9 | 23 |
|
10 |
| -constresult=awaitclient.mutate({ |
| 24 | +constresult=awaitclient.mutate<AuthenticateData,AuthenticateVariables>({ |
11 | 25 | mutation:authenticateMutation,
|
12 | 26 | variables:{
|
13 | 27 | machineId:context.env.machineId,
|
14 | 28 | sessionId:context.env.sessionId,
|
15 | 29 | editor:'VSCODE',
|
16 | 30 | }
|
17 |
| -}) |
18 |
| - |
| 31 | +}).catch(console.error) |
19 | 32 |
|
20 | 33 | if(!result||!result.data){
|
21 | 34 | // TODO: handle failed authentication
|
22 | 35 | console.error('ERROR: Authentication failed')
|
| 36 | +return |
23 | 37 | }
|
24 | 38 | const{token}=result.data.editorLogin
|
25 | 39 | // add token to headers
|
|