Skip to content
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

implemented more auth methods to login , jwt create and change password #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
40 changes: 39 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const client = new Client()
.setKey('YOUR_API_KEY'); // Replace with your API Key
//.setJWT('jwt'); // Use this to authenticate with JWT generated from Client SDK

const randomEmail = `user-${Math.random().toString(36).substring(7)}@example.com`;

const databases = new Databases(client);
const functions = new Functions(client);
const storage = new Storage(client);
Expand All @@ -21,6 +23,7 @@ let databaseId;
let collectionId;
let documentId;
let userId;
let sessionId;
let bucketId;
let fileId;
let functionId;
Expand Down Expand Up @@ -365,7 +368,7 @@ const createUser = async () => {

const response = await users.create(
ID.unique(),
new Date().getTime() + '@example.com',
randomEmail,
null,
'user@123',
'Some User'
Expand Down Expand Up @@ -415,6 +418,38 @@ const deleteUser = async () => {
console.log(response);
}

const loginUsingEmailPassword = async () => {
console.log(chalk.greenBright('Running Login Using Email Password API'));

const response = await account.createEmailPasswordSession(
randomEmail,
'user@123'
);

sessionId = response.$id;
console.log(response);
}

const createJwt = async () => {

console.log(chalk.greenBright('Running JWT API'));

const response = await users.createJWT(userId, sessionId);
console.log(response);
};

const changeUserPassword = async () => {

console.log(chalk.greenBright('Running Change Password API'));

const response = await users.updatePassword(
userId,
"Pass@101"
);

console.log(response)
};

const createFunction = async () => {
console.log(chalk.greenBright('Running Create Function API'));

Expand Down Expand Up @@ -553,6 +588,9 @@ const runAllTasks = async () => {
await listUsers();
await getUser();
await updateUserName();
await loginUsingEmailPassword();
await createJwt();
await changeUserPassword();
await deleteUser();

await createFunction();
Expand Down