login-signup-google 1.0.0 → 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.
@@ -0,0 +1,42 @@
1
+ import React, { useEffect } from "react";
2
+ export default function GoogleLogin({
3
+ clientId,
4
+ onSuccess
5
+ }) {
6
+ useEffect(() => {
7
+ if (!clientId) {
8
+ console.error("Google Client ID missing");
9
+ return;
10
+ }
11
+
12
+ // Avoid loading script multiple times
13
+ if (document.getElementById("google-gsi-script")) {
14
+ initGoogle();
15
+ return;
16
+ }
17
+ const script = document.createElement("script");
18
+ script.id = "google-gsi-script";
19
+ script.src = "https://accounts.google.com/gsi/client";
20
+ script.async = true;
21
+ script.defer = true;
22
+ document.body.appendChild(script);
23
+ script.onload = initGoogle;
24
+ function initGoogle() {
25
+ if (!window.google) return;
26
+ window.google.accounts.id.initialize({
27
+ client_id: clientId,
28
+ callback: response => {
29
+ onSuccess && onSuccess(response);
30
+ }
31
+ });
32
+ window.google.accounts.id.renderButton(document.getElementById("googleBtn"), {
33
+ theme: "outline",
34
+ size: "large",
35
+ width: 300
36
+ });
37
+ }
38
+ }, [clientId, onSuccess]);
39
+ return /*#__PURE__*/React.createElement("div", {
40
+ id: "googleBtn"
41
+ });
42
+ }
package/dist/Login.js ADDED
@@ -0,0 +1,67 @@
1
+ import React, { useState } from "react";
2
+ export default function Login({
3
+ onLogin
4
+ }) {
5
+ const [email, setEmail] = useState("");
6
+ const [password, setPassword] = useState("");
7
+ const submit = e => {
8
+ e.preventDefault();
9
+ if (!email || !password) {
10
+ alert("All fields required");
11
+ return;
12
+ }
13
+ onLogin && onLogin({
14
+ email,
15
+ password
16
+ });
17
+ };
18
+ return /*#__PURE__*/React.createElement("div", {
19
+ style: styles.card
20
+ }, /*#__PURE__*/React.createElement("h2", {
21
+ style: styles.title
22
+ }, "Login"), /*#__PURE__*/React.createElement("form", {
23
+ onSubmit: submit
24
+ }, /*#__PURE__*/React.createElement("input", {
25
+ style: styles.input,
26
+ placeholder: "Email",
27
+ value: email,
28
+ onChange: e => setEmail(e.target.value)
29
+ }), /*#__PURE__*/React.createElement("input", {
30
+ style: styles.input,
31
+ type: "password",
32
+ placeholder: "Password",
33
+ value: password,
34
+ onChange: e => setPassword(e.target.value)
35
+ }), /*#__PURE__*/React.createElement("button", {
36
+ style: styles.btn
37
+ }, "Login")));
38
+ }
39
+ const styles = {
40
+ card: {
41
+ width: 320,
42
+ padding: 20,
43
+ background: "#fff",
44
+ borderRadius: 10,
45
+ border: "2px solid #2ecc71"
46
+ },
47
+ title: {
48
+ textAlign: "center",
49
+ color: "#2ecc71"
50
+ },
51
+ input: {
52
+ width: "100%",
53
+ padding: 10,
54
+ marginBottom: 10,
55
+ border: "1px solid #2ecc71",
56
+ borderRadius: 5
57
+ },
58
+ btn: {
59
+ width: "100%",
60
+ padding: 10,
61
+ background: "#2ecc71",
62
+ color: "#fff",
63
+ border: "none",
64
+ borderRadius: 5,
65
+ cursor: "pointer"
66
+ }
67
+ };
package/dist/Signup.js ADDED
@@ -0,0 +1,111 @@
1
+ import React, { useState } from "react";
2
+ export default function Signup({
3
+ onSuccess
4
+ }) {
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 => {
29
+ e.preventDefault();
30
+ if (!form.otp) {
31
+ alert("Enter OTP");
32
+ return;
33
+ }
34
+ setSuccess(true);
35
+ onSuccess && onSuccess(form);
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
+ }
46
+ return /*#__PURE__*/React.createElement("div", {
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",
62
+ style: styles.input,
63
+ placeholder: "Email",
64
+ onChange: handleChange
65
+ }), /*#__PURE__*/React.createElement("input", {
66
+ name: "phone",
67
+ style: styles.input,
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
78
+ }), /*#__PURE__*/React.createElement("button", {
79
+ style: styles.btn,
80
+ onClick: submit
81
+ }, "Verify & Signup")));
82
+ }
83
+ const styles = {
84
+ card: {
85
+ width: 350,
86
+ padding: 20,
87
+ background: "#fff",
88
+ borderRadius: 10,
89
+ border: "2px solid #2ecc71"
90
+ },
91
+ title: {
92
+ textAlign: "center",
93
+ color: "#2ecc71"
94
+ },
95
+ input: {
96
+ width: "100%",
97
+ padding: 10,
98
+ marginBottom: 10,
99
+ border: "1px solid #2ecc71",
100
+ borderRadius: 5
101
+ },
102
+ btn: {
103
+ width: "100%",
104
+ padding: 10,
105
+ background: "#2ecc71",
106
+ color: "#fff",
107
+ border: "none",
108
+ borderRadius: 5,
109
+ cursor: "pointer"
110
+ }
111
+ };
@@ -1,4 +1,3 @@
1
- // src/index.js
2
- export { default as Login } from "./Login";
3
- export { default as Signup } from "./Signup";
4
- export { default as GoogleLogin } from "./GoogleLogin";
1
+ export { default as Login } from "./Login";
2
+ export { default as Signup } from "./Signup";
3
+ export { default as GoogleLogin } from "./GoogleLogin";
package/package.json CHANGED
@@ -1,13 +1,28 @@
1
1
  {
2
2
  "name": "login-signup-google",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Reusable React Login, Signup and Google Login components",
5
- "main": "src/index.js",
6
- "keywords": ["react", "login", "signup", "google-auth"],
7
- "author": "Your Name",
5
+ "main": "dist/index.js",
6
+ "keywords": [
7
+ "react",
8
+ "login",
9
+ "signup",
10
+ "google-auth"
11
+ ],
12
+ "author": "sowjanya",
8
13
  "license": "MIT",
9
-
10
14
  "peerDependencies": {
11
15
  "react": ">=18"
16
+ },
17
+ "scripts": {
18
+ "build": "babel src --out-dir dist --extensions .js,.jsx"
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "devDependencies": {
24
+ "@babel/cli": "^7.28.6",
25
+ "@babel/core": "^7.28.6",
26
+ "@babel/preset-react": "^7.28.5"
12
27
  }
13
28
  }
@@ -1,26 +0,0 @@
1
- // src/GoogleLogin.jsx
2
- import { useEffect } from "react";
3
-
4
- export default function GoogleLogin({ clientId, onSuccess }) {
5
- useEffect(() => {
6
- const script = document.createElement("script");
7
- script.src = "https://accounts.google.com/gsi/client";
8
- script.async = true;
9
- script.defer = true;
10
- document.body.appendChild(script);
11
-
12
- script.onload = () => {
13
- window.google.accounts.id.initialize({
14
- client_id: clientId,
15
- callback: onSuccess,
16
- });
17
-
18
- window.google.accounts.id.renderButton(
19
- document.getElementById("googleBtn"),
20
- { theme: "outline", size: "large" }
21
- );
22
- };
23
- }, [clientId, onSuccess]);
24
-
25
- return <div id="googleBtn"></div>;
26
- }
package/src/Login.jsx DELETED
@@ -1,12 +0,0 @@
1
- // src/Login.jsx
2
- export default function Login({ onLogin }) {
3
- return (
4
- <div>
5
- <h3>Login</h3>
6
- <input placeholder="Email" />
7
- <input type="password" placeholder="Password" />
8
- <button onClick={onLogin}>Login</button>
9
- </div>
10
- );
11
- }
12
-
package/src/Signup.jsx DELETED
@@ -1,12 +0,0 @@
1
- // src/Signup.jsx
2
- export default function Signup({ onSignup }) {
3
- return (
4
- <div>
5
- <h3>Signup</h3>
6
- <input placeholder="Email" />
7
- <input type="password" placeholder="Password" />
8
- <button onClick={onSignup}>Signup</button>
9
- </div>
10
- );
11
- }
12
-