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 #23

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
344 changes: 262 additions & 82 deletions client/package-lock.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -9,12 +9,17 @@
"preview": "vite preview"
},
"dependencies": {
"@react-oauth/google": "^0.5.1",
"@vitejs/plugin-basic-ssl": "^1.0.1",
"axios": "^1.2.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-modal": "^3.16.1",
"react-router-dom": "^6.4.3"
"react-router-dom": "^6.4.3",
"zustand": "^4.2.0"
},
"devDependencies": {
"@types/axios": "^0.14.0",
"@types/react": "^18.0.22",
"@types/react-dom": "^18.0.7",
"@vitejs/plugin-react": "^2.2.0",
44 changes: 44 additions & 0 deletions client/src/components/Google/Google.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react'
import { GoogleOAuthProvider } from '@react-oauth/google';
import { GoogleLogin } from '@react-oauth/google';
import axios from "axios";
import { useStore } from "../Hooks/useStore";
import { useNavigate } from "react-router-dom";



const Google = () => {

let navigate = useNavigate();
const redirectToProfile = () => {
navigate("/profile");
};
const setAuthData = useStore((state) => state.setAuthData);
return (
<GoogleOAuthProvider clientId='102813787652-o551ule1i3vdqfkrk4slpcf4rgd8330n.apps.googleusercontent.com'>
<GoogleLogin
useOneTap
onSuccess={async (credentialResponse) => {
console.log("google login clicked");
console.log(credentialResponse);
const googleResponse = await axios.post('http://localhost:8080/googlelogin',{
token: credentialResponse.credential
});
const data = googleResponse.data;

localStorage.setItem("authData", JSON.stringify(data));
setAuthData(data);

console.log(data);
//redirectToProfile();
}}
onError={() => {
console.log('Login Failed');
}}

/>
</GoogleOAuthProvider>
)
}

export default Google
10 changes: 10 additions & 0 deletions client/src/components/Hooks/useStore.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import create from 'zustand'

export const useStore = create((set) => ({

authData: localStorage.getItem('authData') ? JSON.parse(localStorage.getItem('authData')): null,

setAuthData: (newAuthData) => set(state => ({authData: newAuthData}))


}));
9 changes: 8 additions & 1 deletion client/src/components/Login/Login.jsx
Original file line number Diff line number Diff line change
@@ -3,8 +3,13 @@ import FormField from "../FormField/FormField";
import styles from "./Login.module.css";
import { useNavigate } from "react-router-dom";
import { useGlobalContext } from "../../context/GlobalContext";
import Google from "../Google/Google";


const Login = () => {



const { userInfo, setUserInfo } = useGlobalContext();

const [userData, setUserData] = useState({
@@ -119,9 +124,11 @@ const Login = () => {
</div>
</form>
<a href="#" className={styles.forgotten_password}>
Glemt adgangskode?
Glemt adgangskode? {<br />} {<br />}
</a>
<Google />
</section>

</main>
);
};
10 changes: 9 additions & 1 deletion client/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import basicSsl from '@vitejs/plugin-basic-ssl'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()]
plugins: [react(),basicSsl()],


server: {

port: 8080,

}
})
Loading