Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions apps/extension/src/api/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,33 @@ export const postArticles = async (payload: {
const response = await apiRequest.post('/api/v1/articles', payload);
return response.data;
};

export const postCategories = async (payload: { categoryName: string }) => {
const response = await apiRequest.post('/api/v1/categories', payload);
return response.data;
};

export const patchCategories = async ({
categoryId,
categoryName,
}: {
categoryId: number;
categoryName: string;
}) => {
const response = await apiRequest.patch(`/api/v1/categories/${categoryId}`, {
categoryName,
});
return response.data;
};

export const deleteCategories = async ({
categoryId,
}: {
categoryId: number;
}) => {
const response = await apiRequest.delete(
`/api/v1/categories/${categoryId}`,
{}
);
return response.data;
};
31 changes: 22 additions & 9 deletions apps/extension/src/api/axiosInstance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from 'axios';
import { useState } from 'react';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

사용하지 않는 import 제거 필요

useState가 import되었지만 파일 내에서 사용되지 않습니다.

-import { useState } from 'react';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { useState } from 'react';
🤖 Prompt for AI Agents
In apps/extension/src/api/axiosInstance.ts at line 2, the import statement for
useState is present but not used anywhere in the file. Remove the unused import
of useState to clean up the code and avoid unnecessary imports.


const apiRequest = axios.create({
baseURL: import.meta.env.VITE_BASE_URL,
Expand All @@ -14,9 +15,9 @@ const fetchToken = async (email?: string) => {
params: { email },
}
);
const newToken = response.data.token;
const newToken = response.data.data.token;
chrome.storage.local.set({ jwtToken: newToken }, () => {
console.log('Token saved to chrome storage');
console.log('Token saved to chrome storage다시', newToken);
});
return newToken;
};
Expand All @@ -25,15 +26,27 @@ apiRequest.interceptors.request.use(async (config) => {
const noAuthNeeded = ['/api/v1/auth/token', '/api/v1/auth/signup'];
const isNoAuth = noAuthNeeded.some((url) => config.url?.includes(url));

if (!isNoAuth) {
let token =
'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJwaW5iYWNrIiwiaWQiOiJhOTA1NGFjOS03MTg0LTQ3NjktYWY4Mi1jNGViYTg0YzYxYTIiLCJzdWIiOiJBY2Nlc3NUb2tlbiIsImV4cCI6MTc1MjgwMDY1Nn0.hXti-Jlnhg8mRoPl5nB8Vi8UV6HPdZYAtgtpTuqtH39lQWle8T5GlX0ug0nNVUqu5B_Pyzafck7lhfXN6ArHOA';
if (isNoAuth) return config;

if (!token || token === 'undefined') {
token = await fetchToken('test@gmail.com');
}
config.headers.Authorization = `Bearer ${token}`;
const email = await new Promise<string | undefined>((resolve) => {
chrome.storage.local.get('email', (result) => {
resolve(result.email);
});
});

let token = await new Promise<string | undefined>((resolve) => {
chrome.storage.local.get('jwtToken', (result) => {
resolve(result.jwtToken);
});
});

// 토큰 없으면 fetchToken 호출
if (!token || token === 'undefined') {
console.log(email, '여기야');
token = await fetchToken(email);
}

config.headers.Authorization = `Bearer ${token}`;
return config;
});

Expand Down
31 changes: 30 additions & 1 deletion apps/extension/src/api/queries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { getCategoriesDash, postArticles } from './axios';
import {
getCategoriesDash,
postArticles,
postCategories,
patchCategories,
deleteCategories,
} from './axios';
import { useQuery, useMutation } from '@tanstack/react-query';
export const useGetCategoriesDash = () => {
return useQuery({
Expand All @@ -12,3 +18,26 @@ export const usePostArticles = () => {
mutationFn: postArticles,
});
};

export const usePostCategories = () => {
return useMutation({
mutationFn: postCategories,
});
};

interface PatchCategoryParams {
categoryId: number;
categoryName: string;
}

export const usePatchCategories = () => {
return useMutation({
mutationFn: patchCategories,
});
};

export const useDeleteCategories = () => {
return useMutation({
mutationFn: deleteCategories,
});
};
9 changes: 6 additions & 3 deletions apps/extension/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ chrome.runtime.onInstalled.addListener((details) => {
if (details.reason === 'install') {
chrome.identity.getProfileUserInfo(function (info) {
console.log('google email:', info.email);
chrome.storage.local.set({ email: info.email }, () => {
console.log('Token saved!', info.email);
});
setTimeout(() => {
chrome.tabs.create({
url: `http://localhost:5180/onboarding?email=${info.email}`,
url: `http://localhost:5173/onboarding?email=${info.email}`,
});
}, 1000);
});
Expand All @@ -23,7 +26,7 @@ chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
const { url, title } = message.payload;

chrome.storage.local.set({ savedBookmark: url }, () => {
console.log('📦 storage 저장 완료:', url);
console.log('📦 storage 저장 완료:');
});

chrome.bookmarks.create(
Expand All @@ -43,7 +46,7 @@ chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
error: chrome.runtime.lastError.message,
});
} else {
console.log('📦 북마크 저장 완료:', newBookmark);
console.log('📦 북마크 저장 완료:');
sendResponse({ success: true, data: newBookmark });
}
}
Expand Down
Loading