1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-01-16 20:08:15 +01:00

add signup package required for extension auth

This commit is contained in:
Kushagra Gour 2024-05-09 16:54:40 +05:30
parent 3c8bf5e982
commit 346adb54c2
10 changed files with 8399 additions and 0 deletions

1
.gitignore vendored
View File

@ -19,3 +19,4 @@ extension/
yarn-error.log
src/locales/_build
extension-*.zip
.parcel-cache/

View File

@ -222,6 +222,8 @@ gulp.task('buildDistFolder', function (cb) {
child_process.execSync('rm -rf dist');
child_process.execSync('mv packages/website/_site dist');
child_process.execSync(`mv ${APP_FOLDER} dist/`);
child_process.execSync(`mkdir dist/signup`);
child_process.execSync(`cp packages/signup/dist/*.* dist/signup/`);
cb();
});

1187
packages/signup/dist/index.1903c1b7.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1
packages/signup/dist/index.html vendored Normal file
View File

@ -0,0 +1 @@
<!doctype html><html><head><title>signInWithPopup</title></head><body> <h1>signInWithPopup</h1> <script type="module" src="/index.1903c1b7.js"></script> </body></html>

View File

@ -0,0 +1,8 @@
export const config = {
apiKey: 'AIzaSyBl8Dz7ZOE7aP75mipYl2zKdLSRzBU2fFc',
authDomain: 'web-maker-app.firebaseapp.com',
databaseURL: 'https://web-maker-app.firebaseio.com',
projectId: 'web-maker-app',
storageBucket: 'web-maker-app.appspot.com',
messagingSenderId: '560473480645'
};

View File

@ -0,0 +1,11 @@
<!doctype html>
<html>
<head>
<title>signInWithPopup</title>
</head>
<body>
<h1>signInWithPopup</h1>
<script type="module" src="signInWithPopup.js"></script>
</body>
</html>

7140
packages/signup/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,9 @@
{
"dependencies": {
"firebase": "^10.11.1"
},
"devDependencies": {
"parcel": "^2.12.0",
"process": "^0.11.10"
}
}

View File

@ -0,0 +1,39 @@
import {
signInWithPopup,
GithubAuthProvider,
GoogleAuthProvider,
getAuth
} from 'firebase/auth';
import { initializeApp } from 'firebase/app';
import { config } from './firebaseConfig.js';
const app = initializeApp(config);
const auth = getAuth();
// This code runs inside of an iframe in the extension's offscreen document.
// This gives you a reference to the parent frame, i.e. the offscreen document.
// You will need this to assign the targetOrigin for postMessage.
const PARENT_FRAME = document.location.ancestorOrigins[0];
function sendResponse(result) {
globalThis.parent.self.postMessage(JSON.stringify(result), PARENT_FRAME);
}
globalThis.addEventListener('message', function ({ data }) {
if (data.initAuth) {
const { providerName } = data;
let provider;
if (providerName === 'google') {
provider = new GoogleAuthProvider();
provider.addScope('https://www.googleapis.com/auth/userinfo.profile');
} else {
provider = new GithubAuthProvider();
}
// Opens the Google sign-in page in a popup, inside of an iframe in the
// extension's offscreen document.
// To centralize logic, all respones are forwarded to the parent frame,
// which goes on to forward them to the extension's service worker.
signInWithPopup(auth, provider).then(sendResponse).catch(sendResponse);
}
});