mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-27 23:40:28 +05:30
be08857edc
Handle more errors for device code. Dispatch a BSOD for an any unhandled exception from auth flow state
27 lines
950 B
TypeScript
27 lines
950 B
TypeScript
import AbstractState from './AbstractState';
|
|
import { AuthContext } from './AuthFlow';
|
|
import CompleteState from './CompleteState';
|
|
|
|
export default class DeviceCodeState extends AbstractState {
|
|
async resolve(context: AuthContext, payload: { user_code: string }): Promise<void> {
|
|
const { query } = context.getRequest();
|
|
|
|
return context
|
|
.run('oAuthValidate', {
|
|
params: {
|
|
userCode: payload.user_code,
|
|
},
|
|
description: query.get('description')!,
|
|
prompt: query.get('prompt')!,
|
|
})
|
|
.then(() => context.setState(new CompleteState()))
|
|
.catch((err) => {
|
|
if (['invalid_user_code', 'expired_token', 'used_user_code'].includes(err.error)) {
|
|
return context.run('setErrors', { [err.parameter]: err.error });
|
|
}
|
|
|
|
throw err;
|
|
});
|
|
}
|
|
}
|