API reformatting

This commit is contained in:
Roman Krček
2025-07-02 23:33:35 +02:00
parent c2949e4bfe
commit 878198fabd
8 changed files with 230 additions and 23 deletions

View File

@@ -1,8 +1,8 @@
<script lang="ts">
import { onMount } from 'svelte';
import type { GoogleSheet } from '$lib/sheets.js';
import { isTokenValid, refreshAccessToken } from '$lib/google.js';
import { goto } from '$app/navigation';
import { isTokenValid, refreshAccessToken, getUserInfo, revokeToken } from '$lib/google.js';
import { goto } from '$app/navigation';
// Import Components
import GoogleAuthStep from './components/GoogleAuthStep.svelte';
@@ -190,17 +190,11 @@
async function fetchUserInfo(accessToken: string) {
try {
const response = await fetch('https://www.googleapis.com/oauth2/v2/userinfo', {
headers: {
Authorization: `Bearer ${accessToken}`
}
});
if (response.ok) {
const userData = await response.json();
// Use the new getUserInfo function from our lib
const userData = await getUserInfo(accessToken);
if (userData) {
authData.userEmail = userData.email;
} else {
console.error('Failed to fetch user info:', await response.text());
authData.userEmail = null;
}
} catch (error) {
@@ -211,15 +205,10 @@
async function disconnectGoogle() {
try {
// First revoke the token at Google
// First revoke the token at Google using our API
const accessToken = localStorage.getItem('google_access_token');
if (accessToken) {
await fetch(`https://accounts.google.com/o/oauth2/revoke?token=${accessToken}`, {
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
await revokeToken(accessToken);
}
// Remove tokens from local storage
@@ -308,8 +297,8 @@
sheetsData.expandedSheetList = true;
try {
// TODO: Replace with actual API call
const response = await fetch('/api/sheets/recent', {
// Use the new unified API endpoint
const response = await fetch('/private/api/google/sheets/recent', {
method: 'GET',
headers: {
'Authorization': `Bearer ${localStorage.getItem('google_refresh_token')}`
@@ -339,8 +328,8 @@
}
try {
// TODO: Replace with actual API call
const response = await fetch(`/api/sheets/${sheet.id}/data`, {
// Use the new unified API endpoint
const response = await fetch(`/private/api/google/sheets/${sheet.id}/data`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${localStorage.getItem('google_refresh_token')}`