mirror of
https://github.com/rjNemo/ticket_manager
synced 2026-06-10 18:56:39 +00:00
edit backend to accept string id, create auth/helper to extract userId
This commit is contained in:
parent
e3a1fa0d0a
commit
f415e0626a
11 changed files with 26 additions and 18 deletions
|
|
@ -64,7 +64,7 @@ namespace TicketManager.Controllers
|
|||
[HttpGet("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<ActionResult<AppUserDTO>> GetUser(Guid id)
|
||||
public async Task<ActionResult<AppUserDTO>> 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<IActionResult> PutUser(Guid id, AppUser user)
|
||||
public async Task<IActionResult> PutUser(string id, AppUser user)
|
||||
{
|
||||
if (id != user.Id)
|
||||
{
|
||||
|
|
@ -202,7 +202,7 @@ namespace TicketManager.Controllers
|
|||
}
|
||||
|
||||
[HttpGet("{id}/projects")]
|
||||
public async Task<ActionResult<IEnumerable<ProjectDTORequest>>> GetAppUserProjects(Guid id)
|
||||
public async Task<ActionResult<IEnumerable<ProjectDTORequest>>> 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<ActionResult<IEnumerable<TicketDTORead>>> GetAppUserTickets(Guid id)
|
||||
public async Task<ActionResult<IEnumerable<TicketDTORead>>> 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -271,7 +271,7 @@ namespace TicketManager.Controllers
|
|||
[HttpPatch("{id}/members")]
|
||||
public async Task<ActionResult<Project>> SetProjectMembers(
|
||||
[FromRoute] int id,
|
||||
[FromBody] Guid[] membersId)
|
||||
[FromBody] string[] membersId)
|
||||
{
|
||||
Project project = await _context.Projects
|
||||
.Include(p => p.Assignments)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace TicketManager.Models
|
|||
{
|
||||
public class AppUser
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(50)]
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
|
|
|||
9
client/src/authentication/helpers.ts
Normal file
9
client/src/authentication/helpers.ts
Normal file
|
|
@ -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;
|
||||
};
|
||||
|
|
@ -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<IProps> = ({ 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();
|
||||
|
|
|
|||
|
|
@ -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 <div>HomePage</div>;
|
||||
|
|
|
|||
|
|
@ -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 <Redirect to={`${ROUTES.USERS}/${uid}`} />;
|
||||
} else {
|
||||
return <SignInSide />;
|
||||
|
|
|
|||
Loading…
Reference in a new issue