Skip to content

Commit

Permalink
Changes to auth
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwroge committed Oct 18, 2024
1 parent 868dcdf commit 875e002
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion backend/startup_scripts/setup_moto_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def create(self):
region_name="us-east-1",
aws_access_key_id="testing",
aws_secret_access_key="testing",
endpoint_url=os.environ['COGNITO_ENDPOINT_URL'])
# endpoint_url=os.environ['COGNITO_ENDPOINT_URL']
)

# Only create a user pool and test data if one does not already exist
pools = cognito_client.list_user_pools(MaxResults=5)
Expand Down
1 change: 1 addition & 0 deletions backend/tests/test_alembic_migration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from app.user_roles import UserRole

from app.repositories.user_repo import UserRepository

# Importing these tests will register them within our test project
Expand Down
1 change: 1 addition & 0 deletions frontend/src/features/authentication/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {useCurrentUserQuery} from '../../services/user';

export const ProtectedRoute = ({children}: {children: JSX.Element}) => {
const {user} = useAuth();

const {isLoading} = useCurrentUserQuery();
const location = useLocation();

Expand Down
11 changes: 9 additions & 2 deletions frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,20 @@ import {
} from './pages';
import {SystemAdminDashboard} from './pages/SystemAdminDashboard';
import {enableMocking} from './utils/testing/browser';
import {useAppDispatch} from './redux/hooks/store';
import {setCredentials} from './redux/authSlice';

function HuuApp() {
const [session] = useSessionMutation();

const dispatch = useAppDispatch();
// signin to current session if it exists, otherwise fail silently
React.useEffect(() => {
session();
session()
.unwrap()
.then(res => {
const {token, user} = res;
dispatch(setCredentials({user, token}));
});
}, []);

return (
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/pages/authentication/ConfirmSignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export const ConfirmSignUp = () => {
} catch (err) {
let errorMessage = '';
if (isFetchBaseQueryError(err)) {
errorMessage = err.data.message;
errorMessage =
err.data?.message || `An error occurred in Confirm Sign up`;
} else if (isErrorWithMessage(err)) {
errorMessage = err.message;
}
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/pages/authentication/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export const SignIn = () => {
} catch (err) {
if (isFetchBaseQueryError(err)) {
// you can access all properties of `FetchBaseQueryError` here
const errMsg = err.data.message;
const errMsg =
err.data?.message || 'An unexpected error occured in Sign In';
setErrorMessage(errMsg);
} else if (isErrorWithMessage(err)) {
// you can access a string 'message' property here
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/redux/authSlice.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {createSlice, PayloadAction} from '@reduxjs/toolkit';

// import {User, userAPI} from '../services/user';
import {User} from '../services/user';
import {RootState} from './store';
// import {authApi} from '../services/auth';

interface AuthState {
user: User | null;
Expand Down
4 changes: 2 additions & 2 deletions frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function huuApiBaseUrl(envHuuApiBaseUrl: string, mode: string): URL | never {
return new URL(envHuuApiBaseUrl);
} catch {
if (mode === 'development' || mode === 'test') {
return new URL('http://localhost:8000/api');
return new URL('http://0.0.0.0:8000/api');
} else {
throw new Error('VITE_HUU_API_BASE_URL is not configured with a URL');
}
Expand Down Expand Up @@ -43,7 +43,7 @@ export default defineConfig(({mode}) => {
},
plugins: [react()],
server: {
port: 34828,
port: 4040,
proxy: {
'/api': {
target: apiBaseUrl.origin,
Expand Down

0 comments on commit 875e002

Please sign in to comment.