Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 28 additions & 4 deletions src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,38 @@ import { trackEvent } from './analytics';
import firebase from 'firebase/app';
import { log } from './utils';

const isExtension = typeof chrome !== 'undefined' && !!chrome?.runtime?.id;

function loginWithGoogleInExtension() {
return new Promise((resolve, reject) => {
chrome.identity.getAuthToken({ interactive: true }, (token) => {
if (chrome.runtime.lastError) {
reject(new Error(chrome.runtime.lastError.message));
return;
}
const credential = firebase.auth.GoogleAuthProvider.credential(null, token);
firebase.auth().signInWithCredential(credential).then(resolve).catch(reject);
});
});
}

export const auth = {
logout() {
if (isExtension) {
chrome.identity.clearAllCachedAuthTokens(() => {});
}
firebase.auth().signOut();
},
login(providerName) {
if (isExtension && providerName === 'google') {
return loginWithGoogleInExtension()
.then(() => {
trackEvent('fn', 'loggedIn', providerName);
window.db.local.set({ lastAuthProvider: providerName });
})
.catch(log);
}

var provider;
if (providerName === 'facebook') {
provider = new firebase.auth.FacebookAuthProvider();
Expand All @@ -24,10 +51,7 @@ export const auth = {
.signInWithPopup(provider)
.then(function () {
trackEvent('fn', 'loggedIn', providerName);
// Save to recommend next time
window.db.local.set({
lastAuthProvider: providerName,
});
window.db.local.set({ lastAuthProvider: providerName });
})
.catch(function (error) {
log(error);
Expand Down
62 changes: 34 additions & 28 deletions src/components/LoginModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as Dialog from '@radix-ui/react-dialog';
import { useEffect } from 'preact/hooks';
import mixpanel from '../services/mixpanel';

const isExtension = typeof chrome !== 'undefined' && !!chrome?.runtime?.id;

export default function LoginModal({ open, onClose }) {
const login = (e) => {
const provider = e.target.dataset.authProvider;
Expand Down Expand Up @@ -40,20 +42,22 @@ export default function LoginModal({ open, onClose }) {
</Dialog.Title>
<div className="mt-6 w-full">
<div className="flex flex-col gap-3">
<button
type="button"
onClick={login}
className="flex items-center p-3 gap-2 justify-center w-full rounded-lg border border-neutral-400 hover:bg-black-500/90"
data-auth-provider="github"
data-hint="You logged in with Github last time"
>
<span className="block w-5 h-5">
<svg className="w-full h-full fill-current">
<use xlinkHref="#github-icon" />
</svg>
</span>
Login with Github
</button>
{!isExtension && (
<button
type="button"
onClick={login}
className="flex items-center p-3 gap-2 justify-center w-full rounded-lg border border-neutral-400 hover:bg-black-500/90"
data-auth-provider="github"
data-hint="You logged in with Github last time"
>
<span className="block w-5 h-5">
<svg className="w-full h-full fill-current">
<use xlinkHref="#github-icon" />
</svg>
</span>
Login with Github
</button>
)}
<button
type="button"
onClick={login}
Expand All @@ -68,20 +72,22 @@ export default function LoginModal({ open, onClose }) {
</span>
Login with Google
</button>
<button
type="button"
onClick={login}
class="flex items-center p-3 gap-2 justify-center w-full rounded-lg border border-neutral-400 hover:bg-black-500/90"
data-auth-provider="facebook"
data-hint="You logged in with Facebook last time"
>
<span className="block w-5 h-5">
<svg className="w-full h-full">
<use xlinkHref="#fb-icon" />
</svg>
</span>
Login with Facebook
</button>
{!isExtension && (
<button
type="button"
onClick={login}
className="flex items-center p-3 gap-2 justify-center w-full rounded-lg border border-neutral-400 hover:bg-black-500/90"
data-auth-provider="facebook"
data-hint="You logged in with Facebook last time"
>
<span className="block w-5 h-5">
<svg className="w-full h-full">
<use xlinkHref="#fb-icon" />
</svg>
</span>
Login with Facebook
</button>
)}
<p className="text-center mt-4">
Join a community of 50,000+ Developers
</p>
Expand Down
2 changes: 2 additions & 0 deletions src/components/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const LocalStorageKeys = {
LOGIN_AND_SAVE_MESSAGE_SEEN: 'loginAndsaveMessageSeen',
ASKED_TO_IMPORT_CREATIONS: 'askedToImportCreations',
};

const UNSAVED_WARNING_COUNT = 15;
const version = '3.6.1';

Expand Down Expand Up @@ -1658,6 +1659,7 @@ BookLibService.Borrow(id) {
onUpdateImage={this.onUpdateImage.bind(this)}
currentItem={this.state.currentItem}
onLogin={this.loginBtnClickHandler.bind(this)}

externalLibCount={this.state.externalLibCount}
openBtnHandler={this.openBtnClickHandler.bind(this)}
newBtnHandler={this.newBtnClickHandler.bind(this)}
Expand Down
2 changes: 1 addition & 1 deletion static/landing/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ <h3>UML diagrams</h3>
<a href="privacy_policy.html" target="_blank">Privacy Policy</a>
</div>
</div>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script src="jquery-2.2.4.min.js"></script>
</body>

</html>
4 changes: 4 additions & 0 deletions static/landing/jquery-2.2.4.min.js

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion static/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
"manifest_version": 3,
"description": "Real-time & offline tool for generating sequence diagrams",
"homepage_url": "https://zenuml.com",
"permissions": ["storage"],
"permissions": ["storage", "identity"],
"oauth2": {
"client_id": "REPLACE_WITH_YOUR_GOOGLE_OAUTH_CLIENT_ID.apps.googleusercontent.com",
"scopes": [
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile"
]
},
"options_ui": {
"page": "options.html",
"open_in_tab": false
Expand Down
Loading