Skip to content

Commit 0546539

Browse files
Bert-SunJohnny-Qvictorzheng02
committed
added google login functionality
Co-authored-by: Johnny <[email protected]> Co-authored-by: Victor <[email protected]>
1 parent 3e60b66 commit 0546539

File tree

8 files changed

+36
-4071
lines changed

8 files changed

+36
-4071
lines changed

mysql_sample_db/mysqlsampledatabase.sql

-4,065
This file was deleted.

mysql_sample_db/sample_db.zip

-53.1 KB
Binary file not shown.

src/login.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const {OAuth2Client} = require('google-auth-library');
2+
export {};
3+
let CLIENT_ID : string = "136122883712-eue6mcej6psh8meqkcemd8sklr277544.apps.googleusercontent.com";
4+
const client = new OAuth2Client(CLIENT_ID);
5+
async function verify(token : string) {
6+
const ticket = await client.verifyIdToken({
7+
idToken: token,
8+
audience: CLIENT_ID, // Specify the CLIENT_ID of the app that accesses the backend
9+
// Or, if multiple clients access the backend:
10+
//[CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3]
11+
});
12+
const payload = ticket.getPayload();
13+
14+
return payload;
15+
//const userid = payload['sub'];
16+
// If request specified a G Suite domain:
17+
// const domain = payload['hd'];
18+
}
19+
20+
21+
async function verifyUser(id : string){
22+
console.log("inside");
23+
let payload = await verify(id);
24+
console.log(payload);
25+
// check db for user and insert if not exist, generate user token, return user token
26+
return "ok";
27+
}
28+
29+
module.exports = verifyUser;

src/resolvers.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { rootCertificates } from "tls";
2+
const verifyUser = require("./login");
23

34
export {};
45

@@ -43,6 +44,7 @@ module.exports = {
4344
}
4445
},
4546
Mutation:{
46-
addUser: (_, {displayName }, { dataSources })=> dataSources.db.addUser(displayName)
47+
addUser: (_, {displayName }, { dataSources })=> dataSources.db.addUser(displayName),
48+
login: (_, {id}) => {console.log(id); return verifyUser(id);}
4749
}
4850
}

src/schema.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ const typeDefs = gql`
4545
type Query{
4646
requestTutor(reqBy: ID!, subject: String!, timestamp: String!): RequestTutorReturn
4747
getUserById(id: Int!): UserInterface
48-
getMessageById(id: Int!): Message
48+
getMessageById(id: Int!): Message
4949
hello: String
5050
}
5151
5252
type Mutation{
53+
login(id: String!): String
5354
deleteMessageById(id: ID!): Int!
5455
addUser(displayName: String!): UserInterface
5556
}
56-
`;
57+
`
5758

5859
module.exports = typeDefs;

src/server.ts

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function createStore(){
4646
})
4747
});
4848
})
49+
4950
return db;
5051
}
5152

src/sql_datasource.ts

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class SQLSource extends DataSource {
88
constructor(db){
99
super();
1010
this.store = db;
11-
this.connected = [];
1211
console.log('done');
1312
}
1413
initialize (config){

src/websocket.ts

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ var connected = {
1111
//id: websocket connection
1212
};
1313
wss.on("connection", (ws: WebSocket, req: Request)=>{
14-
var id = req.body.id;
15-
connected[id] = ws;
1614
console.log("websocket connected");
1715
});
1816

0 commit comments

Comments
 (0)