login-signup-google 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,22 +8,33 @@ export default function GoogleLogin({
8
8
  console.error("Google Client ID missing");
9
9
  return;
10
10
  }
11
+
12
+ // Avoid loading script multiple times
13
+ if (document.getElementById("google-gsi-script")) {
14
+ initGoogle();
15
+ return;
16
+ }
11
17
  const script = document.createElement("script");
18
+ script.id = "google-gsi-script";
12
19
  script.src = "https://accounts.google.com/gsi/client";
13
20
  script.async = true;
14
21
  script.defer = true;
15
22
  document.body.appendChild(script);
16
- script.onload = () => {
23
+ script.onload = initGoogle;
24
+ function initGoogle() {
25
+ if (!window.google) return;
17
26
  window.google.accounts.id.initialize({
18
27
  client_id: clientId,
19
- callback: onSuccess
28
+ callback: response => {
29
+ onSuccess && onSuccess(response);
30
+ }
20
31
  });
21
32
  window.google.accounts.id.renderButton(document.getElementById("googleBtn"), {
22
33
  theme: "outline",
23
34
  size: "large",
24
35
  width: 300
25
36
  });
26
- };
37
+ }
27
38
  }, [clientId, onSuccess]);
28
39
  return /*#__PURE__*/React.createElement("div", {
29
40
  id: "googleBtn"
package/dist/Login.js CHANGED
@@ -4,26 +4,25 @@ export default function Login({
4
4
  }) {
5
5
  const [email, setEmail] = useState("");
6
6
  const [password, setPassword] = useState("");
7
- const handleSubmit = e => {
7
+ const submit = e => {
8
8
  e.preventDefault();
9
9
  if (!email || !password) {
10
- alert("Please enter email and password");
10
+ alert("All fields required");
11
11
  return;
12
12
  }
13
-
14
- // send data to parent app
15
13
  onLogin && onLogin({
16
14
  email,
17
15
  password
18
16
  });
19
17
  };
20
18
  return /*#__PURE__*/React.createElement("div", {
21
- style: styles.box
22
- }, /*#__PURE__*/React.createElement("h2", null, "Login"), /*#__PURE__*/React.createElement("form", {
23
- onSubmit: handleSubmit
19
+ style: styles.card
20
+ }, /*#__PURE__*/React.createElement("h2", {
21
+ style: styles.title
22
+ }, "Login"), /*#__PURE__*/React.createElement("form", {
23
+ onSubmit: submit
24
24
  }, /*#__PURE__*/React.createElement("input", {
25
25
  style: styles.input,
26
- type: "email",
27
26
  placeholder: "Email",
28
27
  value: email,
29
28
  onChange: e => setEmail(e.target.value)
@@ -34,26 +33,35 @@ export default function Login({
34
33
  value: password,
35
34
  onChange: e => setPassword(e.target.value)
36
35
  }), /*#__PURE__*/React.createElement("button", {
37
- style: styles.button,
38
- type: "submit"
36
+ style: styles.btn
39
37
  }, "Login")));
40
38
  }
41
39
  const styles = {
42
- box: {
43
- width: 300,
40
+ card: {
41
+ width: 320,
44
42
  padding: 20,
45
- border: "1px solid #ddd",
46
- borderRadius: 8,
47
- marginBottom: 20
43
+ background: "#fff",
44
+ borderRadius: 10,
45
+ border: "2px solid #2ecc71"
46
+ },
47
+ title: {
48
+ textAlign: "center",
49
+ color: "#2ecc71"
48
50
  },
49
51
  input: {
50
52
  width: "100%",
51
- padding: 8,
52
- marginBottom: 10
53
+ padding: 10,
54
+ marginBottom: 10,
55
+ border: "1px solid #2ecc71",
56
+ borderRadius: 5
53
57
  },
54
- button: {
58
+ btn: {
55
59
  width: "100%",
56
60
  padding: 10,
61
+ background: "#2ecc71",
62
+ color: "#fff",
63
+ border: "none",
64
+ borderRadius: 5,
57
65
  cursor: "pointer"
58
66
  }
59
67
  };
package/dist/Signup.js CHANGED
@@ -1,57 +1,111 @@
1
1
  import React, { useState } from "react";
2
2
  export default function Signup({
3
- onSignup
3
+ onSuccess
4
4
  }) {
5
- const [email, setEmail] = useState("");
6
- const [password, setPassword] = useState("");
7
- const handleSubmit = e => {
5
+ const [form, setForm] = useState({
6
+ firstName: "",
7
+ lastName: "",
8
+ email: "",
9
+ phone: "",
10
+ otp: ""
11
+ });
12
+ const [otpSent, setOtpSent] = useState(false);
13
+ const [success, setSuccess] = useState(false);
14
+ const handleChange = e => {
15
+ setForm({
16
+ ...form,
17
+ [e.target.name]: e.target.value
18
+ });
19
+ };
20
+ const sendOtp = () => {
21
+ if (!form.phone) {
22
+ alert("Enter phone number");
23
+ return;
24
+ }
25
+ setOtpSent(true);
26
+ alert("OTP sent (demo)");
27
+ };
28
+ const submit = e => {
8
29
  e.preventDefault();
9
- if (!email || !password) {
10
- alert("Please enter email and password");
30
+ if (!form.otp) {
31
+ alert("Enter OTP");
11
32
  return;
12
33
  }
13
- onSignup && onSignup({
14
- email,
15
- password
16
- });
34
+ setSuccess(true);
35
+ onSuccess && onSuccess(form);
17
36
  };
37
+ if (success) {
38
+ return /*#__PURE__*/React.createElement("div", {
39
+ style: styles.card
40
+ }, /*#__PURE__*/React.createElement("h2", {
41
+ style: {
42
+ color: "#2ecc71"
43
+ }
44
+ }, "Signup Successful \u2705"), /*#__PURE__*/React.createElement("p", null, "Welcome ", form.firstName));
45
+ }
18
46
  return /*#__PURE__*/React.createElement("div", {
19
- style: styles.box
20
- }, /*#__PURE__*/React.createElement("h2", null, "Signup"), /*#__PURE__*/React.createElement("form", {
21
- onSubmit: handleSubmit
22
- }, /*#__PURE__*/React.createElement("input", {
47
+ style: styles.card
48
+ }, /*#__PURE__*/React.createElement("h2", {
49
+ style: styles.title
50
+ }, "Signup"), /*#__PURE__*/React.createElement("input", {
51
+ name: "firstName",
52
+ style: styles.input,
53
+ placeholder: "First Name",
54
+ onChange: handleChange
55
+ }), /*#__PURE__*/React.createElement("input", {
56
+ name: "lastName",
57
+ style: styles.input,
58
+ placeholder: "Last Name",
59
+ onChange: handleChange
60
+ }), /*#__PURE__*/React.createElement("input", {
61
+ name: "email",
23
62
  style: styles.input,
24
- type: "email",
25
63
  placeholder: "Email",
26
- value: email,
27
- onChange: e => setEmail(e.target.value)
64
+ onChange: handleChange
28
65
  }), /*#__PURE__*/React.createElement("input", {
66
+ name: "phone",
29
67
  style: styles.input,
30
- type: "password",
31
- placeholder: "Password",
32
- value: password,
33
- onChange: e => setPassword(e.target.value)
68
+ placeholder: "Phone Number",
69
+ onChange: handleChange
70
+ }), !otpSent ? /*#__PURE__*/React.createElement("button", {
71
+ style: styles.btn,
72
+ onClick: sendOtp
73
+ }, "Send OTP") : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("input", {
74
+ name: "otp",
75
+ style: styles.input,
76
+ placeholder: "Enter OTP",
77
+ onChange: handleChange
34
78
  }), /*#__PURE__*/React.createElement("button", {
35
- style: styles.button,
36
- type: "submit"
37
- }, "Signup")));
79
+ style: styles.btn,
80
+ onClick: submit
81
+ }, "Verify & Signup")));
38
82
  }
39
83
  const styles = {
40
- box: {
41
- width: 300,
84
+ card: {
85
+ width: 350,
42
86
  padding: 20,
43
- border: "1px solid #ddd",
44
- borderRadius: 8,
45
- marginBottom: 20
87
+ background: "#fff",
88
+ borderRadius: 10,
89
+ border: "2px solid #2ecc71"
90
+ },
91
+ title: {
92
+ textAlign: "center",
93
+ color: "#2ecc71"
46
94
  },
47
95
  input: {
48
96
  width: "100%",
49
- padding: 8,
50
- marginBottom: 10
97
+ padding: 10,
98
+ marginBottom: 10,
99
+ border: "1px solid #2ecc71",
100
+ borderRadius: 5
51
101
  },
52
- button: {
102
+ btn: {
53
103
  width: "100%",
54
104
  padding: 10,
105
+ background: "#2ecc71",
106
+ color: "#fff",
107
+ border: "none",
108
+ borderRadius: 5,
55
109
  cursor: "pointer"
56
110
  }
57
111
  };
package/package.json CHANGED
@@ -1,29 +1,25 @@
1
1
  {
2
2
  "name": "login-signup-google",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Reusable React Login, Signup and Google Login components",
5
5
  "main": "dist/index.js",
6
-
7
6
  "keywords": [
8
7
  "react",
9
8
  "login",
10
9
  "signup",
11
10
  "google-auth"
12
11
  ],
13
-
14
12
  "author": "sowjanya",
15
13
  "license": "MIT",
16
-
17
14
  "peerDependencies": {
18
15
  "react": ">=18"
19
16
  },
20
-
21
17
  "scripts": {
22
18
  "build": "babel src --out-dir dist --extensions .js,.jsx"
23
19
  },
24
-
25
- "files": ["dist"],
26
-
20
+ "files": [
21
+ "dist"
22
+ ],
27
23
  "devDependencies": {
28
24
  "@babel/cli": "^7.28.6",
29
25
  "@babel/core": "^7.28.6",