Open PESolut opened 1 month ago
done: if a user is not signed in, nothing will happen when adding items to cart next step: a user is redirected to the sign in view upon adding item when not signed in note: i remember issues with navigation; does navigation.push work here or should we clear the navigation stack before pushing the sign in page; intuitively it makes sense to clear the stack.
navigation.dispatch(
CommonActions.reset({
index: 0,
routes: [{ name: 'Dispensaries' }],
}))
when we navigate; we want to clear the stack since we are changing views, replace Dispensaries
with SignIn
done: a user is redirected to the sign in componenent upon adding a item to the basket next step: populate the sign in comp with unstyled html data
done: ' unstyled html added to signin ' next step: style the sign in
done ' email stage of sign in complete '
next step: design and formulate the sign in system logic
notes:
i see the system as the following:
a user is directed to the sign in view
1)upon component mount; state is init for stage
and new
default state for stage is 1 and default state for new is null
2) user is asked for input; upon input given; check input
3) if email input exists; go to stage 2, if not, go to stage 2 with new state set as true
4) if stage==2, dynamic render signInForm2.js prompting for user input for password; upon input given;
5)checkinput, if new == null, find user that has that password; if not found, take input again.
5a) if found, set stage == 0
6) checkinput, if new == true
7) if stage == 0, take userInput and based on new value, either post a new user and sign that user in and redirect to home or sign in that user and redirect to home
i've implemented the basis of this system; all that is left is to :
these functions will happen on the backend as the following:
on the backend we have four functions for handling auth; doesAccountExist might handle the functionality we need....
const doesAccountExist = async (req, res, next) => {
const { email } = req.body;
const credentials = await getLoginByEmail(email)
// if there is no error message = there is an account, so send error message
if(credentials.email) {
res.status(401).json({ error: ` there is an account already linked to ${email}`})
} else {
console.log('account does not exist')
next();
}
}
I'm sure if i change this, something somewhere else will break... we can however; send a request to this and work with the response for our functionality
backend crashed when peforming request with just the email... upon checking the logs it seems its the request to check the email without a value for the password causing the error
/app/node_modules/bcrypt/bcrypt.js:144
error = new Error('data must be a string or Buffer and salt must either be a salt string or a number of rounds');
^
Error: data must be a string or Buffer and salt must either be a salt string or a number of rounds
at Object.hash (/app/node_modules/bcrypt/bcrypt.js:144:17)
at /app/node_modules/bcrypt/promises.js:29:12
at new Promise (<anonymous>)
at module.exports.promise (/app/node_modules/bcrypt/promises.js:20:12)
at Object.hash (/app/node_modules/bcrypt/bcrypt.js:133:25)
at /app/middleware/auth.js:50:10
// CHECK IF USER EXISTS
clientUser.post("/check-email", doesAccountExist, async (req, res) => {
// If middleware passes (account doesn't exist), send success response
res.status(200).json({ message: "Email is available" });
});
Added new route to check email availability without requiring password:
POST /users/check-email
- Checks if email exists in databasedoesAccountExist
middlewareCreated this instead of modifying registration endpoint to handle missing password cases.
... Reflecting these changes on backend then going to retry the stage 1 of login system
success! a user can go through stage 1 of the login system, email is being checked actively with 1 revision needed (outside the scope of this ticket so ill complete later ) testing that our 'new' state works as expected
A user can now successfully trigger loginForm2
after completing stage 1 of the login system. The transition is smooth and provides clear visual feedback.
Implement the basic structure of loginForm2
by:
When proceeding beyond stage 2, we have access to:
At its current capacity; the signInFormButton only submits to email; lets make it so we can define a type. for now this button can have two types: email or password.
...
done: 'signInFromButton multi-use...' next: actually post new accounts; then sign in.
{API}/users/ POST
clientUser.post("/", hashPass, doesAccountExist, async (req, res) => {
const newClientUser = await createClientUser(req.body)
if(!newClientUser.message){
res.status(200).json(newClientUser)
}
else {
res.status(500).json({error: newClientUser.message})
}
})
const createClientUser = async (clientUser) => {
try {
const newClientUser = await db.one(
"INSERT INTO client_user (Name, Address, Latitude, Longitude, email, password) VALUES ($1, $2, $3, $4, $5, $6) RETURNING *",
[
clientUser.name,
clientUser.address,
clientUser.latitude,
clientUser.longitude,
clientUser.email,
clientUser.password
]
);
return newClientUser;
} catch (error) {
return error;
}
};
lets get into signInForm2, build our userDetails state and submit will blank values for name address and lat and long.
creating createNewUser function within SignIn.js to post to BE
hashPass middleware is not properly handling the Promise chain. It's not waiting for the hash to be set before calling next()... fixing...
done: hashpass bugfix: nextsteps: test createNewUser Functionality.
done: a user is able to register a new account and is redirected without their token next-step: log the new user in after registering by attaching the res.response.token to state userID within provider
A user should be able to freely browse through the application without signing in. However, upon attempting to add an item to their cart, they should be prompted to sign in. This ensures users are authenticated before they engage in purchase-related actions.
Acceptance Criteria
Tasks