Skip to content

Commit

Permalink
Desktop: Make sure clipper authorisation notification is displayed, e…
Browse files Browse the repository at this point in the history
…ven when in config screen
  • Loading branch information
laurent22 committed Jul 19, 2021
1 parent bddbc0b commit b2de27b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/app-desktop/gui/ClipperConfigScreen.jsx
Expand Up @@ -40,6 +40,17 @@ class ClipperConfigScreenComponent extends React.Component {
alert(_('Token has been copied to the clipboard!'));
}

componentDidUpdate(prevProps) {
if (prevProps.needApiAuth !== this.props.needApiAuth && this.props.needApiAuth) {
// Ideally when API auth is needed, we should display the
// notification in this screen, however it's not setup for it yet.
// So instead, we just go back to the main screen where the
// notification will be displayed.
// https://discourse.joplinapp.org/t/web-clipper-2-1-3-not-working/18582/27
this.props.dispatch({ type: 'NAV_BACK' });
}
}

renewToken_click() {
if (confirm(_('Are you sure you want to renew the authorisation token?'))) {
void EncryptionService.instance()
Expand Down Expand Up @@ -171,6 +182,7 @@ const mapStateToProps = state => {
clipperServer: state.clipperServer,
clipperServerAutoStart: state.settings['clipperServer.autoStart'],
apiToken: state.settings['api.token'],
needApiAuth: state.needApiAuth,
};
};

Expand Down
2 changes: 2 additions & 0 deletions packages/lib/services/rest/Api.ts
Expand Up @@ -132,6 +132,8 @@ export default class Api {
}

public acceptAuthToken(accept: boolean) {
if (!this.authToken_) throw new Error('Auth token is not set');

this.authToken_.status = accept ? AuthTokenStatus.Accepted : AuthTokenStatus.Rejected;

this.dispatch_({
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/services/rest/routes/auth.ts
Expand Up @@ -19,7 +19,7 @@ export default async function(request: Request, id: string = null, _link: string
if (request.method === 'GET') {
if (id === 'check') {
if ('auth_token' in request.query) {
if (request.query.auth_token === context.authToken.value) {
if (context.authToken && request.query.auth_token === context.authToken.value) {
const output: any = {
status: context.authToken.status,
};
Expand Down

0 comments on commit b2de27b

Please sign in to comment.