-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathauth-client.ts
97 lines (89 loc) · 1.74 KB
/
auth-client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import * as grpc from '@grpc/grpc-js';
import customConfig from "../server/config/default";
import { proto } from "./app";
const client = new proto.AuthService(
`0.0.0.0:${customConfig.port}`,
grpc.credentials.createInsecure()
);
const deadline = new Date();
deadline.setSeconds(deadline.getSeconds() + 5);
client.waitForReady(deadline, (err) => {
if (err) {
console.error(err);
return;
}
onClientReady();
});
function onClientReady() {
verifyEmail("484aed90efbb9beff8dcd693d18c8ca7231c0527")
}
function signUpUser() {
client.SignUpUser(
{
name: 'Admin',
email: 'admin@admin.com',
password: 'password123',
passwordConfirm: 'password123',
photo: 'default.png',
},
(err, res) => {
if (err) {
console.error(err);
return;
}
console.log(res);
}
);
}
function signInUser({email, password}:{email: string, password: string}) {
client.SignInUser(
{
email,
password,
},
(err, res) => {
if (err) {
console.error(err);
return;
}
console.log(res);
}
);
}
function refreshToken(refresh_token: string) {
client.RefreshToken(
{
refresh_token,
},
(err, res) => {
if (err) {
console.error(err);
return;
}
console.log(res);
}
);
}
function getAuthenticatedUser(access_token: string) {
client.getMe(
{
access_token,
},
(err, res) => {
if (err) {
console.error(err);
return;
}
console.log(res);
}
);
}
function verifyEmail(verification_code: string) {
client.verifyEmail({ verification_code }, (err, res) => {
if (err) {
console.error(err);
return;
}
console.log(res);
});
}