Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add social login support for web #831

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Add social login support for web
  • Loading branch information
danim1130 committed Oct 2, 2024
commit 7273b5b78b6df585cb05febc2b31bc9c7f47ccef
11 changes: 11 additions & 0 deletions src/renderer/lib/auth.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
sendPasswordResetEmail,
signInAnonymously,
signInWithCredential,
signInWithPopup,
signOut,
} from "firebase/auth";
import { FirebaseError } from "firebase/app";
Expand Down Expand Up @@ -102,6 +103,15 @@ const createAuth = () => {
}
}

async function googleLoginPopup() {
await signInWithPopup(
getCurrentCentralAuth(),
new GoogleAuthProvider()
).catch((error) => {
console.log(error);
});
}

async function logout() {
await signOut(getCurrentCentralAuth()).catch((error) => {
console.log(error);
Expand Down Expand Up @@ -154,6 +164,7 @@ const createAuth = () => {
getCurrentAuthEnvironment,
setCurrentAuthEnvironment,
sendForgottenPasswordLink,
googleLoginPopup,
};
};

Expand Down
15 changes: 11 additions & 4 deletions src/renderer/main/modals/UserLogin.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
});
}

function socialLogin() {
if (import.meta.env.VITE_WEB_MODE) {
authStore.googleLoginPopup();
} else {
window.electron.openInBrowser(
$appSettings.persistent.profileCloudUrl + "/authorize"
);
}
}

function forgottenPassword() {
if (!email) {
loginError = "Input email to send the password reset to!";
Expand Down Expand Up @@ -120,10 +130,7 @@

<button
class="self-center rounded flex items-center justify-start font-medium bg-emerald-600 hover:bg-emerald-700"
on:click={() =>
window.electron.openInBrowser(
$appSettings.persistent.profileCloudUrl + "/authorize"
)}
on:click={() => socialLogin()}
>
<div class="w-14 h-14 p-1">
<svg
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/preload-window-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ if (import.meta.env.VITE_WEB_MODE == "true") {

restartPackageManager: () => {},
resetAppSettings: () => {},
openInBrowser: () => {},
openInBrowser: (url) => {
window.open(url, "_blank").focus();
},
overlay: () => {},
};
}
Expand Down
Loading