Skip to content

Completed Login function #3

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"body-parser": "^1.20.0",
"bootstrapt": "^1.2.0",
"core-js": "^3.8.3",
"cors": "^2.8.5",
"crypto-browserify": "^3.12.0",
"crypto-js": "^4.1.1",
"ethers": "^5.6.9",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/fa-font/css/fontawesome.min.css

Large diffs are not rendered by default.

Empty file.
249 changes: 204 additions & 45 deletions src/components/Login/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import VueMetamask from 'vue-metamask';
import axios from 'axios'
import { ethers } from 'ethers'
import { error } from 'console';
// import { response } from 'express';


export default {
data() {
return {
name: "Connect wallet"
name: "Connect wallet",
provider: null
}
},

Expand All @@ -19,52 +16,214 @@ export default {
},

methods: {
connect: async function () {
const { ethereum } = window;
if (!ethereum) {
alert("Get MetaMask!");
return;
async connect() {

// const solWindow = window.solana;

// if (solWindow?.isPhantom) {
// this.provider = solWindow
// }

// connecting to phantom

const solana = window.solana;

if (!solana) {
window.open("https://phantom.app/download", "_blank");
} else {
await solana.connect();

// defining and encoding message
const message = new TextEncoder().encode("Welcome to CryptoForum, sign this message to login!");

// signing the message
const signedMessage = await solana.signMessage(message, "utf8");

// getting the data
const publicKey = signedMessage.publicKey.toBase58();
const signature = signedMessage.signature.toString("hex");

// console.log(publicKey);
// console.log(signature);


const options = {
url: 'https://forum.leet-auth.dev/authenticate',
method: 'POST',
headers : {
'content-type': 'application/json',
'Accept': 'application/json'
},
body : {
"publicKey": publicKey,
"signature": signature
},
}

axios.post(
'https://forum.leet-auth.dev/authenticate',
JSON.stringify({publicKey: publicKey, signature: signature}),
{
headers: {
'Content-Type': 'application/json',
'Accept': '*/*'
}
}
)
.then((res) => {
console.log("we are here!!!")
console.log("response" + res.status)

//Send the request
this.name =signature.toString().slice(0, 5) + "..." + signature.toString().slice(-6, -1)

//
this.$store.state = res.data.sessionKey;

// console.log(this.$store.state)
})
.catch((err) => {
console.log("we are here!!!")
console.error('Login failed.', err);
})

}
// after this u send them to the server

//Get public_key
const accounts = await ethereum.request({
method: "eth_requestAccounts",
});
// if (!solWindow) {
// window.open("https://phantom.app/download", "_blank");
// } else {
// solWindow?.connect()
// .then(res=> {

// //Get a signature
// const encodedMessage = new TextEncoder().encode("Welcome to CryptoForum, sign this message to login!");
// const signedMessage = window.solana.request({
// method: "signMessage",
// params: {
// message: encodedMessage,
// display: "utf8", //hex,utf8
// },
// });

const publickey = accounts[0]
// signedMessage.then(res => {
// const options = {
// url: 'https://forum.leet-auth.dev/authenticate',
// method: 'POST',
// body : {
// "publicKey": base58(res.publicKey),
// "signature": convertToHex(res.signature)
// },
// }

// function convertToHex(str) {
// var hex = '';
// for(var i=0;i<str.length;i++) {
// hex += ''+str.charCodeAt(i).toString(16);
// }
// return hex;
// }

// console.log(options);

// this.$axios(options)
// .then((res) => {
// console.log("we are here!!!")
// console.log('Login suceeded!', res.data)
// })
// .catch((err) => {
// console.log("we are here!!!")
// console.error('Login failed.', err);
// })

// })

// })
// .catch((err) => {
// console.error("connect ERROR:", err);
// });
// }


// const { ethereum } = window;
// if (!ethereum) {
// alert("Get MetaMask!");
// return;
// }

// //Get public_key
// const accounts = await ethereum.request({
// method: "eth_requestAccounts",
// });

//Get a signature
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = await provider.getSigner();
const signature = await signer.signMessage("Please confirm your login ");
// const provider = new ethers.providers.Web3Provider(window.ethereum);
// const signer = await provider.getSigner();
// const signature = await signer.signMessage("Please confirm your login ");

//wallet conenct
this.$refs.metamask.init();

//Send the request
await(this.name = publickey.slice(0, 5) + "..." + publickey.slice(-6, -1))
if (publickey != null) {
axios.post("https://forum.leet-auth.dev/authenticate", { publickey, signature }).then((response) => {
console.log("sssssssssssssssssssssssssss")
console.log(response.data)
})
// const request = {
// method: "POST",
// headers: {
// 'Accept': '/',
// 'Content-Type': 'application/json'
// },
// body: JSON.stringify({
// "publickey": publickey,
// "signature": signature,
// })
// }

// fetch("https://forum.leet-auth.dev/authenticate", request).then(res => res.json()).catch(console.error)
}
else {
return;
}
// //wallet conenct
// this.$refs.metamask.init();

// // const header = {
// // 'Access-Control-Allow-Origin': '*',
// // 'Access-Control-Allow-Methods': 'OPTIONS, DELETE, POST, GET, PATCH, PUT',
// // 'Access-Control-Allow-Credentials': true,
// // 'Access-Control-Allow-Headers': 'Content-Type',
// // }

// //Send the request
// await(this.name = publickey.slice(0, 5) + "..." + publickey.slice(-6, -1))
// if (publickey != null) {
// // axios.defaults.baseURL = "https://forum.leet-auth.dev/";
// // axios.defaults.headers.post["Content-Type"] = 'application/json;charset=utf-8';
// // axios.defaults.headers.post['Access-Control-Allow-Origin']='*';

// console.log(base58(publickey), signature);

// const options = {
// url: 'https://forum.leet-auth.dev/authenticate',
// method: 'POST',
// body : {
// "publicKey": base58(publickey),
// "signature": signature.slice(2)
// },
// }

// console.log(options);

// this.$axios(options)
// .then((res) => {
// console.log("we are here!!!")
// console.log('Login suceeded!', res.data)
// })
// .catch((err) => {
// console.log("we are here!!!")
// console.error('Login failed.', err);
// })

// // axios.post(
// // "https://forum.leet-auth.dev/authenticate",
// // { publickey, signature },
// // {header})
// // .then((response) => {
// // console.log("sssssssssssssssssssssssssss")
// // console.log(response.data)
// // });

// // const request = {
// // method: "POST",
// // header,
// // body: JSON.stringify({
// // "publickey": publickey,
// // "signature": signature,
// // })
// // }

// // fetch("https://forum.leet-auth.dev/authenticate", request).then(res => res.json()).catch(console.error)
// }
// else {
// return;
// }
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ module.exports = defineConfig({
}
},
plugins:[new NodePolyfillPlugin()],
},
devServer: {
headers: { 'Access-Control-Allow-Origin': '*' },
proxy: 'https://forum.leet-auth.dev/',
// https: true,
}


})

2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3631,7 +3631,7 @@ core-util-is@~1.0.0:
resolved "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz"
integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==

cors@^2.8.1, cors@^2.8.5:
cors@^2.8.1:
version "2.8.5"
resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29"
integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==
Expand Down