diff --git a/apps/client/src/pages/onBoarding/GoogleCallback.tsx b/apps/client/src/pages/onBoarding/GoogleCallback.tsx index a742e7fe..b4d03e64 100644 --- a/apps/client/src/pages/onBoarding/GoogleCallback.tsx +++ b/apps/client/src/pages/onBoarding/GoogleCallback.tsx @@ -46,9 +46,7 @@ const GoogleCallback = () => { } }; - const redirectUri = import.meta.env.PROD - ? import.meta.env.VITE_GOOGLE_REDIRECT_URI_PROD - : import.meta.env.VITE_GOOGLE_REDIRECT_URI_DEV; + const redirectUri = import.meta.env.VITE_GOOGLE_REDIRECT_URI; const loginWithCode = async (code: string) => { try { diff --git a/apps/client/src/shared/utils/handleGoogleLogin.ts b/apps/client/src/shared/utils/handleGoogleLogin.ts index 8b0ff14b..f70ac974 100644 --- a/apps/client/src/shared/utils/handleGoogleLogin.ts +++ b/apps/client/src/shared/utils/handleGoogleLogin.ts @@ -1,14 +1,13 @@ export const handleGoogleLogin = () => { const clientId = import.meta.env.VITE_GOOGLE_CLIENT_ID; - const redirectUri = import.meta.env.PROD - ? import.meta.env.VITE_GOOGLE_REDIRECT_URI_PROD - : import.meta.env.VITE_GOOGLE_REDIRECT_URI_DEV; + const redirectUri = import.meta.env.VITE_GOOGLE_REDIRECT_URI; if (!clientId || !redirectUri) { alert('Google OAuth 설정이 누락되었습니다.'); return; } + const googleAuthUrl = `https://accounts.google.com/o/oauth2/v2/auth?` + `client_id=${clientId}` + diff --git a/apps/extension/.gitignore b/apps/extension/.gitignore index 800f3a80..7a22cca6 100644 --- a/apps/extension/.gitignore +++ b/apps/extension/.gitignore @@ -15,8 +15,10 @@ # misc .DS_Store .env.local +.env.development .env.development.local .env.test.local +.env.production .env.production.local npm-debug.log* diff --git a/apps/extension/manifest.json b/apps/extension/manifest.json index f0b3aa5a..9ae1f400 100644 --- a/apps/extension/manifest.json +++ b/apps/extension/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "Pinback 핀백 - 북마크 관리와 리마인드 도구", - "version": "1.0.2", + "version": "1.0.3", "action": { "default_popup": "popup.html" }, "icons": { "128": "icon.png", diff --git a/apps/extension/package.json b/apps/extension/package.json index f1f7715f..84779808 100644 --- a/apps/extension/package.json +++ b/apps/extension/package.json @@ -4,11 +4,13 @@ "private": true, "type": "module", "scripts": { - "dev": "vite", - "build": "tsc -b && vite build", + "dev": "vite --mode development", + "build": "pnpm build:prod", + "build:dev": "tsc -b && vite build --mode development", + "build:prod": "tsc -b && vite build --mode production", "lint": "eslint .", "format": "prettier -w .", - "zip": "vite build && node scripts/zip.mjs" + "zip": "pnpm build:prod && node scripts/zip.mjs" }, "dependencies": { "@pinback/contracts": "workspace:*", diff --git a/apps/extension/src/background.ts b/apps/extension/src/background.ts index 42b17fcd..a089b710 100644 --- a/apps/extension/src/background.ts +++ b/apps/extension/src/background.ts @@ -1,5 +1,7 @@ import { EXTENSION_MESSAGE_TYPE } from '@pinback/contracts/extension-messages'; +const webUrl = import.meta.env.VITE_WEB_URL || 'https://pinback.today'; + chrome.runtime.onInstalled.addListener((details) => { if (details.reason === 'install') { chrome.identity.getProfileUserInfo(function (info) { @@ -8,7 +10,7 @@ chrome.runtime.onInstalled.addListener((details) => { }); setTimeout(() => { chrome.tabs.create({ - url: `https://pinback.today/onboarding?email=${info.email}`, + url: `${webUrl}/onboarding?email=${info.email}`, }); }, 1000); }); @@ -21,9 +23,7 @@ chrome.runtime.onMessage.addListener((message) => { console.log('Token saved!'); }); } -}); -chrome.runtime.onMessage.addListener((message) => { if (message.type === EXTENSION_MESSAGE_TYPE.logout) { chrome.storage.local.remove('token', () => { console.log('Token removed!'); diff --git a/apps/extension/src/content.ts b/apps/extension/src/content.ts index 92002d60..30dd9146 100644 --- a/apps/extension/src/content.ts +++ b/apps/extension/src/content.ts @@ -1,23 +1,35 @@ import { EXTENSION_MESSAGE_TYPE } from '@pinback/contracts/extension-messages'; +const ALLOWED_ORIGINS = __ALLOWED_ORIGINS__; + +if (ALLOWED_ORIGINS.length === 0) { + console.warn( + '[Pinback] 허용된 도메인(ALLOWED_ORIGINS) 설정이 비어 있습니다. 토큰 동기화가 작동하지 않으니 .env 파일을 확인해주세요.' + ); +} + window.addEventListener('message', (event) => { if (event.source !== window) return; - if (event.data.type === EXTENSION_MESSAGE_TYPE.setToken) { + + if (!ALLOWED_ORIGINS.includes(event.origin)) return; + + const { type, token } = event.data; + + if (type === EXTENSION_MESSAGE_TYPE.setToken) { chrome.runtime.sendMessage({ type: EXTENSION_MESSAGE_TYPE.setToken, - token: event.data.token, + token, }); - chrome.storage.local.set({ token: event.data.token }, () => { - console.log('Token saved!'); + + chrome.storage.local.set({ token }, () => { + console.log(`[${event.origin}] Token saved!`); }); } -}); -window.addEventListener('message', (event) => { - if (event.source !== window) return; - if (event.data.type === EXTENSION_MESSAGE_TYPE.logout) { + // 토큰 삭제 (로그아웃) + if (type === EXTENSION_MESSAGE_TYPE.logout) { chrome.storage.local.remove('token', () => { - console.log('Token removed!'); + console.log(`[${event.origin}] Token removed!`); }); } }); diff --git a/apps/extension/src/pages/LogOutPop.tsx b/apps/extension/src/pages/LogOutPop.tsx index c515a224..4f8f2e97 100644 --- a/apps/extension/src/pages/LogOutPop.tsx +++ b/apps/extension/src/pages/LogOutPop.tsx @@ -1,6 +1,8 @@ import { Icon } from '@pinback/design-system/icons'; import LogOutImg from '/logout_chippi.svg'; const LogOutPop = () => { + const webUrl = import.meta.env.VITE_WEB_URL || 'https://pinback.today'; + return (