Last active
October 15, 2018 14:31
-
-
Save workfel/7c3ade8158518c661d1bcc8b181852fa to your computer and use it in GitHub Desktop.
nest authentication google by digikare (vuejs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Nest authentication By Digikare</title> | |
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.slim.js"></script> | |
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css"> | |
</head> | |
<body> | |
<div class="container" id="app"> | |
<h1 class="title">Google sign-in with nestJS auth</h1> | |
<div class="columns"> | |
<div class="column is-four-fifths"> | |
<a class="button" v-on:click="googleSignIn()">Sign in with google</a> | |
</div> | |
</div> | |
<div v-if="userFound" class="card"> | |
<div class="card-content"> | |
<div class="media"> | |
<div class="media-left"> | |
<figure class="image is-48x48"> | |
<img v-bind:src="userFound.photo"> | |
</figure> | |
</div> | |
<div class="media-content"> | |
<p class="title is-4">{{userFound.name}}</p> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script> | |
var app2 = new Vue({ | |
el: '#app', | |
data: { | |
userFound: false, | |
socket: null, | |
popup: null | |
}, | |
created: function() { | |
// Init socket session | |
this.socket = io('http://127.0.0.1:8080'); | |
// on response of provider display user authenticated | |
this.socket.on('google', user => { | |
console.log(user); | |
this.userFound = user; | |
this.popup.close(); | |
}) | |
}, | |
methods: { | |
googleSignIn: function() { | |
this.popup = this.openPopup(); | |
}, | |
// Launch popup authentication | |
openPopup: function() { | |
const url = `http://127.0.0.1:8080/auth/google?socketId=${this.socket.id}`; | |
return window.open(url, '', | |
`toolbar=no, location=no, directories=no, status=no, menubar=no, | |
scrollbars=no, resizable=no, copyhistory=no` | |
); | |
} | |
} | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment