diff --git a/Controllers/AppUsersController.cs b/Controllers/AppUsersController.cs index 2c1b759..63bedb2 100644 --- a/Controllers/AppUsersController.cs +++ b/Controllers/AppUsersController.cs @@ -64,7 +64,7 @@ namespace TicketManager.Controllers [HttpGet("{id}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task> GetUser(Guid id) + public async Task> GetUser(string id) { var user = await _context.AppUsers .Include(u => u.Assignments) @@ -103,7 +103,7 @@ namespace TicketManager.Controllers [HttpPut("{id}")] [ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task PutUser(Guid id, AppUser user) + public async Task PutUser(string id, AppUser user) { if (id != user.Id) { @@ -202,7 +202,7 @@ namespace TicketManager.Controllers } [HttpGet("{id}/projects")] - public async Task>> GetAppUserProjects(Guid id) + public async Task>> GetAppUserProjects(string id) { var user = await _context.AppUsers .Include(u => u.Assignments) @@ -218,7 +218,7 @@ namespace TicketManager.Controllers } [HttpGet("{id}/tickets/")] - public async Task>> GetAppUserTickets(Guid id) + public async Task>> GetAppUserTickets(string id) { var user = await _context.AppUsers .Include(u => u.Assignments) @@ -233,7 +233,7 @@ namespace TicketManager.Controllers return user.GetTickets().Select(t => new TicketDTORead(t)).ToList(); } - private bool UserExists(Guid id) + private bool UserExists(string id) { return _context.AppUsers.Any(e => e.Id == id); } diff --git a/Controllers/ProjectsController.cs b/Controllers/ProjectsController.cs index c06bfb0..43800b1 100644 --- a/Controllers/ProjectsController.cs +++ b/Controllers/ProjectsController.cs @@ -271,7 +271,7 @@ namespace TicketManager.Controllers [HttpPatch("{id}/members")] public async Task> SetProjectMembers( [FromRoute] int id, - [FromBody] Guid[] membersId) + [FromBody] string[] membersId) { Project project = await _context.Projects .Include(p => p.Assignments) diff --git a/Models/AppUser.cs b/Models/AppUser.cs index 43e0924..f0f5b93 100644 --- a/Models/AppUser.cs +++ b/Models/AppUser.cs @@ -8,7 +8,7 @@ namespace TicketManager.Models { public class AppUser { - public Guid Id { get; set; } + public string Id { get; set; } [Required] [StringLength(50)] diff --git a/Models/Assignment.cs b/Models/Assignment.cs index d31396e..8be0d17 100644 --- a/Models/Assignment.cs +++ b/Models/Assignment.cs @@ -5,7 +5,7 @@ namespace TicketManager.Models public class Assignment { public AppUser User { get; set; } - public Guid UserId { get; set; } + public string UserId { get; set; } public Project Project { get; set; } public int ProjectId { get; set; } } diff --git a/Resources/AppUser/AppUserDTO.cs b/Resources/AppUser/AppUserDTO.cs index c942884..49c4144 100644 --- a/Resources/AppUser/AppUserDTO.cs +++ b/Resources/AppUser/AppUserDTO.cs @@ -23,7 +23,7 @@ namespace TicketManager.Resources Tickets = user.GetTickets().Select(u => new TicketDTORead(u)).ToList(); } - public Guid Id { get; set; } + public string Id { get; set; } public string FirstName { get; set; } diff --git a/Resources/AppUser/AppUserDTORead.cs b/Resources/AppUser/AppUserDTORead.cs index 494476a..70fb3a0 100644 --- a/Resources/AppUser/AppUserDTORead.cs +++ b/Resources/AppUser/AppUserDTORead.cs @@ -20,7 +20,7 @@ namespace TicketManager.Resources Picture = user.Picture; } - public Guid Id { get; set; } + public string Id { get; set; } public string FirstName { get; set; } diff --git a/Resources/AppUser/NewAppUserDTO.cs b/Resources/AppUser/NewAppUserDTO.cs index 1b146e7..9110195 100644 --- a/Resources/AppUser/NewAppUserDTO.cs +++ b/Resources/AppUser/NewAppUserDTO.cs @@ -4,6 +4,8 @@ namespace TicketManager.Resources { public class NewAppUserDTO { + public string Id { get; set; } + [Required] public string FirstName { get; set; } public string LastName { get; set; } diff --git a/client/src/authentication/helpers.ts b/client/src/authentication/helpers.ts new file mode 100644 index 0000000..3a8a915 --- /dev/null +++ b/client/src/authentication/helpers.ts @@ -0,0 +1,9 @@ +/** + * retrieve userId + * @param user Auth0 user object + */ +export const getUID = (user: any) => { + const { sub } = user; + const uid = sub.split("|")[1]; + return uid; +}; diff --git a/client/src/components/Modals/NewProjectModal.tsx b/client/src/components/Modals/NewProjectModal.tsx index 1c1694c..6477a7f 100644 --- a/client/src/components/Modals/NewProjectModal.tsx +++ b/client/src/components/Modals/NewProjectModal.tsx @@ -3,6 +3,7 @@ import { TextField } from "@material-ui/core"; import { useAuth0 } from "../../authentication/auth0"; import { ProjectService } from "../../services"; import Modal from "./Modal"; +import { getUID } from "../../authentication/helpers"; interface IProps { show: boolean; @@ -21,7 +22,7 @@ const NewProjectModal: FC = ({ show, handleClose }) => { title: title, description: description, endingDate: new Date(endingDate).toISOString(), - managerId: "cd179eb7-3a54-4060-b22c-3e947bdffcbc", // get current User id + managerId: getUID(user), // get current User id }; const token = await getTokenSilently(); diff --git a/client/src/pages/HomePage.tsx b/client/src/pages/HomePage.tsx index 15c753c..57f3804 100644 --- a/client/src/pages/HomePage.tsx +++ b/client/src/pages/HomePage.tsx @@ -1,8 +1,4 @@ import React, { FC } from "react"; -// import { LogInForm } from "../components/LogInForm"; -// import { ProfileSelector } from "../components/ProfileSelector"; -import SignInSide from "../components/SignInSide"; -import { useAuth0 } from "../authentication/auth0"; const HomePage: FC = () => { return
HomePage
; diff --git a/client/src/pages/SigninPage.tsx b/client/src/pages/SigninPage.tsx index c6215b8..59241d2 100644 --- a/client/src/pages/SigninPage.tsx +++ b/client/src/pages/SigninPage.tsx @@ -1,7 +1,8 @@ import React, { FC } from "react"; +import { Redirect } from "react-router-dom"; import SignInSide from "../components/SignInSide"; import { useAuth0 } from "../authentication/auth0"; -import { Redirect } from "react-router-dom"; +import { getUID } from "../authentication/helpers"; import * as ROUTES from "../constants/routes"; const SigninPage: FC = () => { @@ -9,8 +10,7 @@ const SigninPage: FC = () => { if (isAuthenticated) { // retrieve userId - const { sub } = user; - const uid = sub.split("|")[1]; + const uid = getUID(user); return ; } else { return ;