Repository navigation
Expand file tree
/
Copy pathutils.ts
More file actions
56 lines (49 loc) · 1.31 KB
/
Copy pathutils.ts
File metadata and controls
56 lines (49 loc) · 1.31 KB
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
import { Amplify, Auth } from "aws-amplify";
// import awsconfig from "./aws-exports";
import { CognitoUser } from "@aws-amplify/auth";
Amplify.configure(JSON.parse(process.env.NEXT_PUBLIC_AWS_CONFIG as string))
// Amplify.configure(awsconfig)
export const uuid = (): string =>
new Date().getTime().toString(36) + Math.random().toString(36).slice(2);
export const getLabel = (): string => {
let inp = prompt("Enter node text: ");
while (!inp) {
inp = prompt("Enter node text: ");
}
return inp;
};
export async function signUp(username: string, password: string, email: string, name: string): Promise<SignUpData | ErrorData> {
try {
const { user, userConfirmed, userSub } = await Auth.signUp({
username: email,
password,
attributes: {
preferred_username: username,
name: name
}
});
return {
"user": user,
"userConfirmed": userConfirmed,
"userSub": userSub
}
} catch (e: any) {
throw e;
}
}
export async function signIn(username: string, password: string): Promise<CognitoUser | ErrorData> {
try {
const data = await Auth.signIn(username, password);
return data;
} catch (e: any) {
throw e;
}
}
interface SignUpData {
user: CognitoUser;
userConfirmed: boolean;
userSub: string;
}
interface ErrorData {
msg: string;
}