Skip to content

Commit 29868ed

Browse files
author
Vianpyro
committed
Implement login and registration enhancements with session cookie management and redirection
1 parent 89b84dd commit 29868ed

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

components/authentication/Login.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
</form>
77
</template>
88

9+
<script setup>
10+
import { useRouter } from 'vue-router';
11+
12+
const router = useRouter();
13+
</script>
14+
915
<script>
1016
export default {
1117
data() {
@@ -17,7 +23,7 @@ export default {
1723
methods: {
1824
login() {
1925
fetch('http://localhost:5000/auth/login', {
20-
method: 'GET',
26+
method: 'POST',
2127
headers: { 'Content-Type': 'application/json' },
2228
body: JSON.stringify({
2329
email: this.email,
@@ -33,6 +39,14 @@ export default {
3339
})
3440
.then(data => {
3541
console.log('Login successful:', data);
42+
43+
// Create or update session cookies
44+
const accessToken = useCookie('access_token');
45+
const refreshToken = useCookie('refresh_token');
46+
accessToken.value = data.access_token;
47+
refreshToken.value = data.refresh_token;
48+
49+
router.push('/');
3650
})
3751
.catch(error => {
3852
console.error('Error:', error);

components/authentication/Register.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
</form>
2121
</template>
2222

23+
<script setup>
24+
import { useRouter } from 'vue-router';
25+
26+
const router = useRouter();
27+
</script>
28+
2329
<script>
2430
export default {
2531
data() {
@@ -55,6 +61,7 @@ export default {
5561
})
5662
.then(data => {
5763
console.log('Registration successful:', data);
64+
router.push('/');
5865
})
5966
.catch(error => {
6067
console.error('Error:', error);

pages/account.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ export default {
1313
const router = useRouter();
1414
1515
const logout = () => {
16+
// Remove session cookies
1617
const accessToken = useCookie('access_token');
1718
const refreshToken = useCookie('refresh_token');
18-
19-
// Remove cookies
2019
accessToken.value = null;
2120
refreshToken.value = null;
2221

0 commit comments

Comments
 (0)