Skip to content

Commit

Permalink
fixing invalid account login bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Kitty-001 committed Jun 18, 2024
1 parent fcfc9dc commit e031fa3
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.6 on 2024-06-18 08:42

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('budget_tracking', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='transaction',
name='update_wallet',
field=models.BooleanField(default=True),
),
]
1 change: 1 addition & 0 deletions backend/budget_tracking/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ def create_from_json(data: dict, user_pk: int) -> 'Transaction':

if data.get("type"):
transaction.type = data.get("type")

if data.get("date"):
date_string = data.get("date")
if isinstance(date_string, datetime):
Expand Down
1 change: 1 addition & 0 deletions backend/users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

urlpatterns = [
path('signup/', views.signup, name="signup"),
path('verify/', views.verification, name="verification"),
]
12 changes: 11 additions & 1 deletion backend/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.contrib.auth import get_user_model
import random
from rest_framework.decorators import permission_classes, api_view
from rest_framework.permissions import AllowAny
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework_simplejwt.tokens import RefreshToken


Expand Down Expand Up @@ -37,3 +37,13 @@ def signup(request):
return JsonResponse({'error': str(e)}, status=405)

# Create your views here.


@api_view(['GET'])
@permission_classes([IsAuthenticated])
def verification(request):
if request.method == 'GET':
return JsonResponse({
'success': "valid account, persist loggedin",
})

18 changes: 18 additions & 0 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,26 @@ import "react-toastify/dist/ReactToastify.css";
import ResetPassword from "./pages/ResetPassword";
import Profile from "./pages/Profile";
import Protected from "./pages/Protected";
import { useEffect } from "react";
import useAxiosPrivate from "./hooks/useAxiosPrivate";
import { useAuth } from "./contexts/AuthContext";

const App = () => {
const apiPrivate = useAxiosPrivate();
const { Logout } = useAuth();

useEffect(() => {
const verify = async () => {
try {
const response = await apiPrivate.get('/users/verify/');
} catch (error) {
console.log("Invalid credential: " + error);
Logout();
}
};

verify();
},[]);

return (
<div className="md:h-screen #d1fae5">
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/AppNavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import UserIcon from "../images/user.png";
import { useNavigate } from "react-router-dom";
import CashFlowIcon from "../images/cashflow.png"
import { useAuth } from "../contexts/AuthContext";
import { toast } from "react-toastify";

const AppNavBar = () => {
let navigate = useNavigate();

const { isLoggedIn, user, Logout } = useAuth();

const handleLogout = () => {
Logout(localStorage.getItem("id"));
Logout();
toast.success("Logout Successfully!");
navigate("/");
};

Expand Down
1 change: 0 additions & 1 deletion frontend/src/contexts/AuthContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const AuthContextProvider = ({ children }) => {
localStorage.setItem("isLoggedIn", "true");
setUser(decodedToken);
setIsLoggedIn(true);

console.log(authTokens.access);
};

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/pages/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ const Login = () => {
console.log("Login response get!");
const { access, refresh } = response.data;
Login({ access, refresh });
toast.success("Login Successfully!");
} catch (error) {
console.error('Login failed: ', error);
toast.error("Login failed: Invalid email or password!")
toast.error("Login failed: Invalid email or password!");
}

};
Expand Down

0 comments on commit e031fa3

Please sign in to comment.