mirror of
https://github.com/gabehf/BudgetBuddy.git
synced 2026-03-07 21:48:14 -08:00
implemented remember me feature
updated the login page to have functional remember me feature
This commit is contained in:
parent
0125f6f9f7
commit
f23ad0bb25
1 changed files with 21 additions and 5 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useState } from 'react'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { Container } from 'react-bootstrap'
|
||||
import './Login.css'
|
||||
|
||||
|
|
@ -6,6 +6,12 @@ export default function Login() {
|
|||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [errorText, setErrorText] = useState(null);
|
||||
const [checked, setChecked] = useState(false);
|
||||
|
||||
// toggles state of checked for checkbox remember me feature
|
||||
const handleCheckbox = () => {
|
||||
setChecked(!checked);
|
||||
}
|
||||
|
||||
function handleSubmit(event) {
|
||||
event.preventDefault();
|
||||
|
|
@ -25,9 +31,18 @@ export default function Login() {
|
|||
console.log(data.error);
|
||||
setErrorText(data.error);
|
||||
} else {
|
||||
const session = data.session;
|
||||
document.cookie = `session=${session}; path=/;`
|
||||
window.location.href = '/dashboard';
|
||||
if(checked) {
|
||||
// the user chose Remember Me, cookie will expire in 7 days
|
||||
const session = data.session;
|
||||
const expires = (new Date(Date.now()+ 604800*1000)).toUTCString();
|
||||
document.cookie = `session=${session}; expires=${expires}; path=/;`
|
||||
window.location.href = '/dashboard';
|
||||
}
|
||||
else {
|
||||
const session = data.session;
|
||||
document.cookie = `session=${session}; path=/;`
|
||||
window.location.href = '/dashboard';
|
||||
}
|
||||
}
|
||||
console.log(data); // Log the response from the server
|
||||
})
|
||||
|
|
@ -69,8 +84,9 @@ export default function Login() {
|
|||
type="checkbox"
|
||||
className="custom-control-input"
|
||||
id="customCheck1"
|
||||
onChange={handleCheckbox}
|
||||
/>
|
||||
<label id="remember-me" className="custom-control-label" htmlFor="customCheck1">
|
||||
<label id="remember-me" className="custom-control-label" htmlFor="customCheck1">
|
||||
Remember me
|
||||
</label>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue