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

Google signup options #1335

Draft
wants to merge 4 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 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
37 changes: 37 additions & 0 deletions src/common/pages/sign-up.scss
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,43 @@
}
}
}
.google-signup-btn {
background-color: #ffffff;
border-radius: 4px;
border: 1px solid #dcdcdc;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.25);
color: #5f6368;
cursor: pointer;
display: inline-block;
font-family: Roboto, sans-serif;
font-size: 14px;
font-weight: 500;
height: 39px;
line-height: 36px;
margin-bottom: 12px;
padding: 0 24px;
text-align: center;
text-decoration: none;
width: 100%;
}
.google-signup-btn:hover {
background-color: #f5f5f5;
}
.google-icon-wrapper {
display: inline-block;
height: 18px;
margin-right: 10px;
width: 18px;
}
.google-icon {
border-radius: 2px;
height: 100%;
width: 100%;
}
.btn-text {
margin: 0;
padding: 0;
}
}

.card {
Expand Down
43 changes: 43 additions & 0 deletions src/common/pages/sign-up.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ enum Stage {
BUY_ACCOUNT = "buy-account"
}

declare var google: any;

export const SignUp = (props: PageProps) => {
const [lsReferral, setLsReferral] = useLocalStorage<string>(PREFIX + "_referral");

Expand Down Expand Up @@ -154,6 +156,37 @@ export const SignUp = (props: PageProps) => {
}
};

const handleSignUpClick = () => {
const client = google.accounts.oauth2.initTokenClient({
client_id: "106495050489-tm2kep6d89h1m1o4ejvmqcnh3qeusf02.apps.googleusercontent.com",
scope: "https://www.googleapis.com/auth/userinfo.email",
ux_mode: "redirect",
prompt: "consent",
include_granted_scopes: true,
callback: (response: any) => {
const requestOptions = {
method: "GET",
headers: {
Authorization: `Bearer ${response.access_token}`,
"Content-Type": "application/json"
}
};

fetch("https://www.googleapis.com/oauth2/v3/userinfo", requestOptions)
.then((response) => response.json())
.then((data) => {
setEmail(data.email);
const userName = data.name
? data.name.toLowerCase().replace(/\s+/g, "")
: data.email.split("@")[0];
setUsername(userName);
})
.catch((err) => error(err));
}
});
client.requestAccessToken();
};

return (
<>
<Meta title={_t("sign-up.header")} />
Expand Down Expand Up @@ -300,6 +333,16 @@ export const SignUp = (props: PageProps) => {
<></>
)}
</Form>
<Button className="google-signup-btn" onClick={handleSignUpClick}>
<span className="google-icon-wrapper">
<img
className="google-icon"
src="https://upload.wikimedia.org/wikipedia/commons/5/53/Google_%22G%22_Logo.svg"
alt="Google logo"
/>
</span>
<span className="btn-text">Sign up with Google</span>
</Button>
<div className="text-center">
{_t("sign-up.login-text-1")}
<a className="pl-1" href="#" onClick={(e) => props.toggleUIProp("login")}>
Expand Down
1 change: 1 addition & 0 deletions src/server/template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const render = (req: express.Request, state: AppState) => {
}]
}
</script>
<script src="https://accounts.google.com/gsi/client"></script>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess We have to use this https://www.npmjs.com/package/google-auth-library instead of current because this lib contains all functions to manipulating with auth/user

<style>
body {
display: block !important;
Expand Down