- Give the signed up user a logged in status.
- Let the logged in user permission to update his/her profile data. Don't mix.
How to check if values match with DB and update column in Vue? Laravel API
I'm sending a code to the user when signing up to their email. The code has its own column in the database saved with the users other info. Before transporting the user to the VerifyPage I'm storing the associated email with Vuex so its displayed when the user reach the VerifyPage for adding the code to change the accounts status from 0 to 1.
The data from the api shows in consol.log but i cant match the database data with the code that is manually typed in and the stored email that follow the user from the signup page.
the code i provide down here give Error: response.data.find is not a function . Tried many different codes but all shows errors or nothing at all. No idea how to get around this. Feels so simple but cant find the solution.
Tried GET and PATCH with the api Route too and it doesnt work.
Route::match(['GET', 'POST'], '/users', [AuthController::class, 'users']);
<script setup>
import { ref } from 'vue';
import { useStore } from 'vuex';
import axios from 'axios';
import { useRouter } from 'vue-router';
import { toastController } from '@ionic/vue';
const router = useRouter();
const store = useStore();
const verificationCode = ref('');
const userEmail = store.getters.userEmail;
const verifyCode = async () => {
try {
// Call the API
const response = await axios.get('http://localhost:8000/api/users');
// Get the user data from response
const user = response.data.find(u => u.email === userEmail);
// Verify email and code match
if (user && user.email === userEmail &&
user.verificationCode === verificationCode.value) {
// Call API to update status
await axios.get(`http://localhost:8000/api/users/${user.id}`, {
status: 1
});
// Redirect to confirmation page
router.push('/login');
} else {
// Not verified, show error
showToast('Error: Invalid verification code');
}
} catch (error) {
console.error('Error:', error.message);
showToast('Error: Failed to verify signup');
}
}
const showToast = async (message) => {
const toast = await toastController.create({
message: message,
position: 'top',
duration: 5000, // Duration in milliseconds
color: 'danger' // Customize color
});
await toast.present();
};
</script>
TABLE `users` (`id`, `name`, `email`, `email_verified_at`, `password`, `gender`, `preference`, `answer`, `age`, `profileimg`, `country`, `city`, `minage`, `maxage`, `language`, `code`, `status`, `remember_token`, `created_at`, `updated_at`) VALUES
(1, 'kicki', '[email protected]', NULL, 'password', 'female', 'both', 'a', '1995', 'profile_1712877770.jpg', 'Albania', 'a', '22', '25', 'Afrikaans', '256654', 0, NULL, '2024-04-11 21:22:50', '2024-04-11 21:22:50');
Please or to participate in this conversation.