Skip to content

Commit

Permalink
Refactor: Consolidate user email domain and tidy up constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Sampiiiii committed Apr 25, 2024
1 parent 87a8238 commit e717749
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
8 changes: 4 additions & 4 deletions apps/anvil/src/auth/authentication/strategies/jwt.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Injectable, UnauthorizedException } from "@nestjs/common";
import { PassportStrategy } from "@nestjs/passport";
import {ExtractJwt, JwtFromRequestFunction, Strategy} from "passport-jwt";
import { ExtractJwt, JwtFromRequestFunction, Strategy } from "passport-jwt";
import { JwtPayload } from "../../interfaces/jwtpayload.interface";
import { UsersService } from "@/users/users.service";
import type { User } from "@ignis/types/users";
import { Request } from 'express'
import { Request } from "express";

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
Expand All @@ -27,8 +27,8 @@ export class JwtStrategy extends PassportStrategy(Strategy) {

const cookieExtractor: JwtFromRequestFunction = (request: Request): string | null => {
let token = null;
if (request && request.cookies) {
token = request.cookies['access_token'];
if (request?.cookies) {
token = request.cookies.access_token;
}
return token;
};
5 changes: 4 additions & 1 deletion apps/forge/src/components/navbar/userNav/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
DropdownMenuTrigger,
} from "@ui/components/ui/dropdown-menu";
import { useSelector } from "react-redux";
import { USER_EMAIL_DOMAIN } from "@/config/constants.ts";

function isString(value: unknown): value is string {
return typeof value === "string";
Expand All @@ -39,7 +40,9 @@ export function UserNav() {
<DropdownMenuLabel className="font-normal">
<div className="flex flex-col space-y-1.5">
<p className="text-sm font-medium leading-none">{user.display_name}</p>
<p className="text-xs leading-none text-muted-foreground">{user.email}@sheffield.ac.uk</p>
<p className="text-xs leading-none text-muted-foreground">
{user.email}@{USER_EMAIL_DOMAIN}
</p>
<div className="flex-wrap flex gap-2">
{user.roles.map((role) => (
<Badge className="">{role.name}</Badge>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Badge } from "@ui/components/ui/badge.tsx";
import { PartialUserWithTeams } from "@ignis/types/users.ts";
import * as React from "react";
import { USER_EMAIL_DOMAIN } from "@/config/constants.ts";

interface AdminDisplayProps {
user: PartialUserWithTeams;
Expand All @@ -18,7 +19,10 @@ export const AdminDisplay: React.FC<AdminDisplayProps> = ({ user }) => {
</Badge>
</div>
<Badge variant="outline" className="rounded-sm shadow-md flex-col">
<span className="text-accent-foreground">Email</span> <span>{user.email}@sheffield.ac.uk</span>
<span className="text-accent-foreground">Email</span>{" "}
<span>
{user.email}@{USER_EMAIL_DOMAIN}
</span>
</Badge>
</div>
);
Expand Down
4 changes: 0 additions & 4 deletions apps/forge/src/config/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
export const AUTH_SESSION_COOKIE = "auth_session";

export const USER_EMAIL_DOMAIN = "sheffield.ac.uk";

export const AUTH_COOKIE_EXPIRES = 7;

export const SIGN_IN_REASONS_STORAGE_KEY = "sign_in_reasons";

export const iForgeEpoch = new Date(Date.UTC(2015, 1, 1));

0 comments on commit e717749

Please sign in to comment.