Skip to content

Commit

Permalink
fix: retry auth with different credentials
Browse files Browse the repository at this point in the history
fix #296
  • Loading branch information
Vinzent03 committed Sep 15, 2022
1 parent 6914830 commit f8da5f4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/isomorphicGit.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import git, { AuthCallback, Errors, GitHttpRequest, GitHttpResponse, GitProgressEvent, HttpClient, Walker } from "isomorphic-git";
import git, { AuthCallback, AuthFailureCallback, Errors, GitHttpRequest, GitHttpResponse, GitProgressEvent, HttpClient, Walker } from "isomorphic-git";
import { Notice, requestUrl } from 'obsidian';
import { GitManager } from "./gitManager";
import ObsidianGit from './main';
import { MyAdapter } from './myAdapter';
import { BranchInfo, FileStatusResult, PluginState, Status, UnstagedFile, WalkDifference } from "./types";
import { GeneralModal } from "./ui/modals/generalModal";
import { worthWalking } from "./utils";


Expand Down Expand Up @@ -41,6 +42,7 @@ export class IsomorphicGit extends GitManager {
fs: MyAdapter,
dir: string,
onAuth: AuthCallback,
onAuthFailure: AuthFailureCallback,
http: HttpClient,
} {
return {
Expand All @@ -52,6 +54,23 @@ export class IsomorphicGit extends GitManager {
password: this.plugin.localStorage.getPassword()
};
},
onAuthFailure: async () => {
new Notice("Authentication failed. Please try with different credentials");
const username = await new GeneralModal(app, [], "Specify your username").open();
if (username) {
const password = await new GeneralModal(app, [], "Specify your password/personal access token").open();
if (password) {
this.plugin.settings.username = username;
await this.plugin.saveSettings();
this.plugin.localStorage.setPassword(password);
return {
username,
password
};
}
}
return { cancel: true };
},
http: {
async request({
url,
Expand Down
5 changes: 5 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Errors } from "isomorphic-git";
import { debounce, Debouncer, EventRef, Menu, normalizePath, Notice, Platform, Plugin, TAbstractFile, TFile } from "obsidian";
import { PromiseQueue } from "src/promiseQueue";
import { ObsidianGitSettingsTab } from "src/settings";
Expand Down Expand Up @@ -1045,6 +1046,10 @@ export default class ObsidianGit extends Plugin {
console.log(`git obsidian message: ${message}`);
}
displayError(message: any, timeout: number = 10 * 1000): void {
if (message instanceof Errors.UserCanceledError) {
new Notice("Aborted");
return;
}
// Some errors might not be of type string
message = message.toString();
new Notice(message, timeout);
Expand Down

0 comments on commit f8da5f4

Please sign in to comment.