Skip to content

Commit fad9e4e

Browse files
committed
Fix storage path for auth code
1 parent 3402921 commit fad9e4e

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

src/config/settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default {
1616
paths: {
1717
access_token: "access_token.db",
1818
tasks: "tasks.json",
19-
authcode: "auth_code.txt",
19+
authcode: "auth_code.db",
2020
user_profile: "user_profile.json",
2121
}
2222
},

src/helpers/auth.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { invoke, shell } from "@tauri-apps/api";
1+
import { shell } from "@tauri-apps/api";
22
import axios from "axios";
33
import { AccessToken, UserProfile } from "../types/googleapis";
44
import { readTextFile, removeFile, writeTextFile, exists } from "@tauri-apps/api/fs";
55
import { CLIENT_ID, CLIENT_SECRET } from "../config/credentials";
66
import settings from "../config/settings";
7+
import { generate_oauth_port, get_access_token, get_auth_code, save_access_token, save_auth_code } from "./invoker";
78

89

910
const DEFAULT_DIRECTORY = settings.fs.DEFAULT_DIRECTORY;
@@ -18,7 +19,7 @@ class PortManager {
1819
return this.port;
1920
}
2021
async generatePort() : Promise<number> {
21-
const port = await invoke("plugin:oauth|start");
22+
const port = await generate_oauth_port();
2223
return port as number;
2324
}
2425
}
@@ -124,7 +125,7 @@ export async function openAuthWindow() {
124125
// save the auth code to storage
125126
export async function saveAuthCode(code: string) {
126127
try {
127-
return await writeTextFile(STORAGE_PATHS.authcode, code, { dir: DEFAULT_DIRECTORY });
128+
return await save_auth_code(code);
128129
} catch (error) {
129130
console.error("Error saving auth code:", error);
130131
throw new Error("Error saving auth code");
@@ -134,7 +135,7 @@ export async function saveAuthCode(code: string) {
134135
// get the auth code from storage
135136
export async function getAuthCode() {
136137
try {
137-
return await readTextFile(STORAGE_PATHS.authcode, { dir: DEFAULT_DIRECTORY });
138+
return await get_auth_code();
138139
} catch (error) {
139140
console.error("Error getting auth code:", error);
140141
return null;
@@ -143,10 +144,8 @@ export async function getAuthCode() {
143144

144145
export async function saveAccessToken(accessToken: string|AccessToken) {
145146
try {
146-
const accessTokenText: string = typeof accessToken === "string" ? accessToken : JSON.stringify(accessToken, null, 2);
147-
console.log(JSON.parse(accessTokenText), "accessTokenText that was saved");
148147
localStorage.setItem("lastLogin", Date.now() + "");
149-
return await invoke("save_access_token", {token: accessTokenText});
148+
return await save_access_token(accessToken);
150149
} catch (error) {
151150
console.error("Error saving access token:", error);
152151
localStorage.removeItem("lastLogin");
@@ -160,7 +159,7 @@ export async function getAccessTokenFromStorage() {
160159
try {
161160
// if file does not exist, return null
162161
if(! await exists(STORAGE_PATHS.access_token, { dir: DEFAULT_DIRECTORY })) throw new Error("File does not exist");
163-
const accessTokenText: string = await invoke('load_access_token')
162+
const accessTokenText: string = (await get_access_token()) as string;
164163
console.log('new access token found')
165164
let accessToken = JSON.parse(accessTokenText) as AccessToken;
166165
// check if the access token is expired

src/helpers/invoker.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ export async function get_auth_code() {
99
return await invoke('get_auth_code');
1010
}
1111

12-
export async function save_auth_token(token: string|AccessToken) {
12+
export async function save_access_token(token: string|AccessToken) {
1313
const accessTokenText: string = typeof token === "string" ? token : JSON.stringify(token, null, 2);
14-
return await invoke('save_auth_token', {token : accessTokenText});
14+
return await invoke('save_access_token', {token : accessTokenText});
1515
}
1616

17-
export async function get_auth_token() {
18-
return await invoke('get_auth_token');
17+
export async function get_access_token() {
18+
return await invoke<String|string>('load_access_token');
1919
}
2020

2121
export async function test_command() {
@@ -24,4 +24,8 @@ export async function test_command() {
2424

2525
export async function greet(name: string) {
2626
return await invoke('greet', {name});
27+
}
28+
29+
export async function generate_oauth_port() {
30+
return await invoke("plugin:oauth|start");
2731
}

src/helpers/windowhelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {showMenu} from "tauri-plugin-context-menu";
33

44
// Disable the right-click menu and text selection.
55
export function loadContextmenu() {
6-
if (window.location.hostname === 'tauri.localhost') {
6+
if (window.location.hostname !== 'tauri.localhost') {
77
return
88
}
99
window.addEventListener("contextmenu", (e) => {

0 commit comments

Comments
 (0)