|
1 | 1 | import*asCRfrom'typings'
|
| 2 | +importclientfrom'../../apollo' |
| 3 | +importauthenticateMutationfrom'../../apollo/mutations/authenticate' |
| 4 | +import{setAuthToken}from'../../apollo/auth' |
| 5 | +import{send}from'xstate' |
2 | 6 |
|
3 | 7 | exportdefault{
|
| 8 | +authenticate:(async(context:CR.MachineContext):Promise<CR.Action>=>{ |
| 9 | +constresult=awaitclient.mutate({ |
| 10 | +mutation:authenticateMutation, |
| 11 | +variables:{ |
| 12 | +machineId:context.env.machineId, |
| 13 | +sessionId:context.env.sessionId, |
| 14 | +editor:'VSCODE', |
| 15 | +} |
| 16 | +}) |
| 17 | + |
| 18 | +if(!result||!result.data){ |
| 19 | +// TODO: handle failed authentication |
| 20 | +console.log('unauthenticated') |
| 21 | +} |
| 22 | +const{token}=result.data.editorLogin |
| 23 | +console.log(token) |
| 24 | +setAuthToken(token) |
| 25 | +returnsend({type:'AUTHENTICATED'}) |
| 26 | +}), |
4 | 27 | userTutorialComplete(context:CR.MachineContext){
|
5 | 28 | console.log('should update user tutorial as complete')
|
6 | 29 | }
|
|