Repository navigation
Expand file tree
/
Copy patherror.tsx
More file actions
347 lines (339 loc) · 11.2 KB
/
Copy patherror.tsx
File metadata and controls
347 lines (339 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
import * as C from '@/constants'
import * as Kb from '@/common-adapters'
import * as React from 'react'
import LoginContainer from '../login/forms/container'
import openURL from '@/util/open-url'
import type {RPCError} from '@/util/errors'
import {Box2, Button, Icon, Text, Markdown} from '@/common-adapters'
import * as T from '@/constants/types'
import {styleSheetCreate, globalStyles, globalMargins, isMobile} from '@/styles'
const ConnectedRenderError = () => {
const _username = C.useAutoResetState(s => s.username)
const error = C.useProvisionState(s => s.finalError)
const startAccountReset = C.useAutoResetState(s => s.dispatch.startAccountReset)
const _onAccountReset = (username: string) => {
startAccountReset(false, username)
}
const navigateUp = C.useRouterState(s => s.dispatch.navigateUp)
const onBack = () => {
navigateUp()
}
const onKBHome = () => {
openURL('https://keybase.io/')
}
const onPasswordReset = () => {
openURL('https://keybase.io/#password-reset')
}
const props = {
error,
onAccountReset: () => _onAccountReset(_username),
onBack,
onKBHome,
onPasswordReset,
}
return <RenderError {...props} />
}
export default ConnectedRenderError
type Props = {
error?: RPCError
onAccountReset: () => void
onBack: () => void
onKBHome: () => void
onPasswordReset: () => void
}
const List = (p: {children: React.ReactNode}) => (
<Box2 direction="vertical" style={styles.list}>
{p.children}
</Box2>
)
const Wrapper = (p: {onBack: () => void; children: React.ReactNode}) => (
<LoginContainer onBack={p.onBack}>
<Icon type="icon-illustration-zen-240-180" style={styles.icon} />
<Text type="Header" style={styles.header}>
Oops, something went wrong.
</Text>
<Box2 direction="vertical" gap="small" gapStart={true} gapEnd={true} style={styles.container}>
{p.children}
</Box2>
{Kb.Styles.isMobile && <Button label="Close" onClick={p.onBack} />}
</LoginContainer>
)
const rewriteErrorDesc = (s: string) => {
switch (s) {
case 'Provisioner is a different user than we wanted.':
return 'Is the other device using the username you expect? It seems to be different.'
default:
return s
}
}
// Normally this would be a component but I want the children to be flat so i can use a Box2 as the parent and have nice gaps
const RenderError = ({error, onBack, onAccountReset, onPasswordReset, onKBHome}: Props) => {
if (!error) {
return (
<Wrapper onBack={onBack}>
<Text center={true} type="Body">
Unknown error: Please report this to us.
</Text>
</Wrapper>
)
}
const f = error.fields as Array<undefined | {key?: string; value?: string}> | undefined
const fields =
f?.reduce<{[key: string]: string}>((acc, f) => {
const k = f && typeof f.key === 'string' ? f.key : ''
acc[k] = f?.value || ''
return acc
}, {}) ?? {}
switch (error.code) {
case T.RPCGen.StatusCode.scdeviceprovisionoffline:
case T.RPCGen.StatusCode.scapinetworkerror:
return (
<Wrapper onBack={onBack}>
<Text center={true} type="Body">
The device authorization failed because this device went offline.
</Text>
<Text center={true} type="Body">
Please check your network connection and try again.
</Text>
</Wrapper>
)
case T.RPCGen.StatusCode.scdevicenoprovision:
return (
<Wrapper onBack={onBack}>
<Text center={true} type="Body">
You can't authorize by password, since you have established device or paper keys.
</Text>
<Text center={true} type="Body">
You can go back and pick a device or paper key, or{' '}
<Text type="BodyPrimaryLink" onClick={onAccountReset}>
reset your account entirely
</Text>
.
</Text>
</Wrapper>
)
case T.RPCGen.StatusCode.scdeviceprevprovisioned:
return (
<Wrapper onBack={onBack}>
<Text center={true} type="Body">
You have already authorized this device.{' '}
</Text>
<Text center={true} type="Body">
Please use 'keybase login [username]' to log in.{' '}
</Text>
</Wrapper>
)
case T.RPCGen.StatusCode.sckeynomatchinggpg:
if (fields['has_active_device']) {
return (
<Wrapper onBack={onBack}>
<Text center={true} type="Body">
You can't authorize using solely a password, since you have active device keys.
</Text>
<Text center={true} type="BodySemibold">
You have options:
</Text>
<List>
<Text center={true} type="Body">
{' '}
- Go back and select a device or paper key
</Text>
<Text center={true} type="Body">
{' '}
- Install Keybase on a machine that has your PGP private key in it
</Text>
<Text center={true} type="Body">
{' '}
- Login to the website and host an encrypted copy of your PGP private key
</Text>
<Text center={true} type="Body">
{' '}
- or,{' '}
<Text type="BodyPrimaryLink" onClick={onAccountReset}>
reset your account entirely
</Text>
.
</Text>
</List>
</Wrapper>
)
} else {
return (
<Wrapper onBack={onBack}>
<Text center={true} type="Body">
You can't authorize using a password, since you've established a PGP key.
</Text>
<Text center={true} type="BodySemibold" style={{textAlign: 'left'}}>
You have options:
</Text>
<List>
<Text center={true} type="Body">
{' '}
- Use <Text type="TerminalInline">keybase login</Text> on the command line to log in
</Text>
{!isMobile && (
<Text center={true} type="Body">
{' '}
- Install GPG on this machine and import your PGP private key into it
</Text>
)}
<Text center={true} type="Body">
{' '}
- Install Keybase on a different machine that has your PGP key
</Text>
<Text center={true} type="Body">
{' '}
- Login to the website and host an encrypted copy of your PGP private key
</Text>
<Text center={true} type="Body">
{' '}
- Or,{' '}
<Text type="BodyPrimaryLink" onClick={onAccountReset}>
reset your account entirely
</Text>
.
</Text>
</List>
</Wrapper>
)
}
case T.RPCGen.StatusCode.sckeynotfound:
return error.desc ? (
<Wrapper onBack={onBack}>
<Markdown>{error.desc}</Markdown>
</Wrapper>
) : (
<Wrapper onBack={onBack}>
<Text center={true} type="Body">
Your PGP keychain has multiple keys installed, and we're not sure which one to use to authorize
your account.
</Text>
<Text center={true} type="Body">
Please run <Text type="TerminalInline">keybase login</Text> on the command line to continue.
</Text>
</Wrapper>
)
case T.RPCGen.StatusCode.scbadloginpassword:
return (
<Wrapper onBack={onBack}>
<Text center={true} type="Body">
Looks like that's a bad password.
</Text>
<Text center={true} type="BodyPrimaryLink" onClick={onPasswordReset}>
Reset your password?
</Text>
</Wrapper>
)
case T.RPCGen.StatusCode.sckeysyncedpgpnotfound:
case T.RPCGen.StatusCode.scgpgunavailable:
case T.RPCGen.StatusCode.sckeynosecret:
return (
<Wrapper onBack={onBack}>
<Text center={true} type="Body">
Sorry, your account is already established with a PGP public key, but we can't access the
corresponding private key.
</Text>
<Text center={true} type="BodySemibold">
You have options:
</Text>
<List>
<Text center={true} type="Body">
{' '}
- Run <Text type="TerminalInline">keybase login</Text> on the device with the corresponding PGP
private key
</Text>
{!isMobile && (
<Text center={true} type="Body">
{' '}
- Install GPG, put your PGP private key on this machine and try again
</Text>
)}
<Text center={true} type="Body">
{' '}
- Go back and authorize with another device or paper key
</Text>
<Text center={true} type="Body">
{' '}
- Or, if none of the above are possible,{' '}
<Text type="BodyPrimaryLink" onClick={onAccountReset}>
reset your account and start fresh
</Text>
</Text>
</List>
</Wrapper>
)
case T.RPCGen.StatusCode.scinputcanceled:
return (
<Wrapper onBack={onBack}>
<Text center={true} type="Body">
Login cancelled.
</Text>
</Wrapper>
)
case T.RPCGen.StatusCode.sckeycorrupted:
return (
<Wrapper onBack={onBack}>
<Text center={true} type="Body">
{error.message}
</Text>
<Text center={true} type="Body">
We were able to generate a PGP signature but it was rejected by the server.
</Text>
<Text type="Body">This often means that this PGP key is expired or unusable.</Text>
<Text center={true} type="Body">
You can update your key on{' '}
<Text type="BodyPrimaryLink" onClick={onKBHome}>
keybase.io
</Text>
.
</Text>
</Wrapper>
)
case T.RPCGen.StatusCode.scdeleted:
return (
<Wrapper onBack={onBack}>
<Text center={true} type="Body">
This user has been deleted.
</Text>
</Wrapper>
)
default:
return (
<Wrapper onBack={onBack}>
<Kb.Box2 direction="vertical">
<Text center={true} type="Body" selectable={true}>
{rewriteErrorDesc(error.desc)}
</Text>
<Text center={true} type="BodySmall" selectable={true}>
{' '}
{error.details}
</Text>
</Kb.Box2>
</Wrapper>
)
}
}
const styles = styleSheetCreate(
() =>
({
container: {
maxWidth: 550,
},
header: {
alignSelf: 'center',
marginBottom: 20,
marginTop: 46,
},
icon: {
alignSelf: 'center',
height: 180,
width: 240,
},
list: {
marginBottom: 10,
marginLeft: globalMargins.tiny,
...globalStyles.flexBoxColumn,
maxWidth: 460,
},
}) as const
)