Skip to content

Commit

Permalink
Merge pull request #36 from jadmsaadaot/SUBMIT-task#24
Browse files Browse the repository at this point in the history
handle user registration by registration link
  • Loading branch information
jadmsaadaot authored Aug 20, 2024
2 parents 23fbc9b + 0c6709a commit 3536bc4
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 8 deletions.
1 change: 0 additions & 1 deletion submit-api/src/submit_api/models/queries/account_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class UserQueries:
@classmethod
def get_by_guid(cls, guid: str):
"""Find user by guid"""
print(guid)
result = (db.session.query(AccountUser)
.filter(AccountUser.auth_guid == guid)
.first())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { CircularProgress } from "@mui/material";
import React from "react";

export const Loader = () => {
export const PageLoader = () => {
return (
<div
style={{
Expand Down
20 changes: 19 additions & 1 deletion submit-web/src/routeTree.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { createFileRoute } from '@tanstack/react-router'
// Import Routes

import { Route as rootRoute } from './routes/__root'
import { Route as RegistrationImport } from './routes/registration'
import { Route as OidcCallbackImport } from './routes/oidc-callback'
import { Route as ErrorImport } from './routes/error'
import { Route as AuthenticatedImport } from './routes/_authenticated'
Expand All @@ -39,6 +40,11 @@ const AuthenticatedDashboardAboutpageLazyImport = createFileRoute(

// Create/Update Routes

const RegistrationRoute = RegistrationImport.update({
path: '/registration',
getParentRoute: () => rootRoute,
} as any)

const OidcCallbackRoute = OidcCallbackImport.update({
path: '/oidc-callback',
getParentRoute: () => rootRoute,
Expand Down Expand Up @@ -169,6 +175,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof OidcCallbackImport
parentRoute: typeof rootRoute
}
'/registration': {
id: '/registration'
path: '/registration'
fullPath: '/registration'
preLoaderRoute: typeof RegistrationImport
parentRoute: typeof rootRoute
}
'/_authenticated/_dashboard': {
id: '/_authenticated/_dashboard'
path: ''
Expand Down Expand Up @@ -279,6 +292,7 @@ export const routeTree = rootRoute.addChildren({
}),
ErrorRoute,
OidcCallbackRoute,
RegistrationRoute,
})

/* prettier-ignore-end */
Expand All @@ -292,7 +306,8 @@ export const routeTree = rootRoute.addChildren({
"/",
"/_authenticated",
"/error",
"/oidc-callback"
"/oidc-callback",
"/registration"
]
},
"/": {
Expand All @@ -314,6 +329,9 @@ export const routeTree = rootRoute.addChildren({
"/oidc-callback": {
"filePath": "oidc-callback.tsx"
},
"/registration": {
"filePath": "registration.tsx"
},
"/_authenticated/_dashboard": {
"filePath": "_authenticated/_dashboard.tsx",
"parent": "/_authenticated",
Expand Down
4 changes: 2 additions & 2 deletions submit-web/src/routes/_authenticated.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Loader } from "@/components/Shared/Loader";
import { PageLoader } from "@/components/Shared/PageLoader";
import { useAccount } from "@/store/accountStore";
import { createFileRoute, Navigate, Outlet } from "@tanstack/react-router";
import { useEffect } from "react";
Expand All @@ -23,7 +23,7 @@ function Auth() {
}, [isAuthenticated, isLoading, signinRedirect, setAccount, proponent_id]);

if (isLoading) {
return <Loader />;
return <PageLoader />;
}

if (!isAuthenticated) {
Expand Down
4 changes: 2 additions & 2 deletions submit-web/src/routes/oidc-callback.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Loader } from "@/components/Shared/Loader";
import { PageLoader } from "@/components/Shared/PageLoader";
import { useGetUserByGuid } from "@/hooks/api/useAccounts";
import { createFileRoute, Navigate } from "@tanstack/react-router";
import { useEffect, useState } from "react";
Expand Down Expand Up @@ -45,5 +45,5 @@ function OidcCallback() {
);
}

return <Loader />;
return <PageLoader />;
}
32 changes: 32 additions & 0 deletions submit-web/src/routes/registration.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { PageLoader } from "@/components/Shared/PageLoader";
import { notify } from "@/components/Shared/Snackbar/snackbarStore";
import { OidcConfig } from "@/utils/config";
import { createFileRoute, Navigate } from "@tanstack/react-router";
import { useEffect } from "react";
import { useAuth } from "react-oidc-context";

export const Route = createFileRoute("/registration")({
component: Registration,
});

function Registration() {
const { isAuthenticated, signinRedirect } = useAuth();
const { proponent_id } = Route.useSearch<{
proponent_id: string;
}>();

useEffect(() => {
if (!proponent_id) {
notify.error("registration link is invalid");
} else if (!isAuthenticated) {
signinRedirect({
redirect_uri: `${OidcConfig.redirect_uri}?proponent_id=${proponent_id}`,
});
}
}, [proponent_id, isAuthenticated, signinRedirect]);

if (isAuthenticated || !proponent_id) {
return <Navigate to={"/error"} />;
}
return <PageLoader />;
}
2 changes: 2 additions & 0 deletions submit-web/src/store/accountStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { create } from "zustand";
interface AccountStoreState {
proponentId: string;
accountId: number;
isLoading: boolean;
setAccount: (account: Partial<AccountStoreState>) => void;
}

export const useAccount = create<AccountStoreState>((set) => ({
proponentId: "",
accountId: 0,
isLoading: true,
setAccount: (account: Partial<AccountStoreState>) =>
set((prev) => ({ ...prev, ...account })),
}));
1 change: 1 addition & 0 deletions submit-web/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const AppConfig = {
environment: APP_ENVIRONMENT,
version: APP_VERSION,
appTitle: APP_TITLE,
appUrl: APP_URL,
};

export const OidcConfig = {
Expand Down

0 comments on commit 3536bc4

Please sign in to comment.