Merge branch 'fix/verschillende-authenticatieproblemen' of https://github.com/SELab-2/Dwengo-1 into fix/verschillende-authenticatieproblemen
This commit is contained in:
commit
58884ade3d
9 changed files with 23 additions and 15 deletions
|
@ -4,7 +4,7 @@ import { AuthenticatedRequest } from '../middleware/auth/authenticated-request.j
|
|||
import { createOrUpdateStudent } from '../services/students.js';
|
||||
import { createOrUpdateTeacher } from '../services/teachers.js';
|
||||
import { envVars, getEnvVar } from '../util/envVars.js';
|
||||
import { Response } from "express";
|
||||
import { Response } from 'express';
|
||||
|
||||
interface FrontendIdpConfig {
|
||||
authority: string;
|
||||
|
@ -43,20 +43,20 @@ export function getFrontendAuthConfig(): FrontendAuthConfig {
|
|||
export async function postHelloHandler(req: AuthenticatedRequest, res: Response): Promise<void> {
|
||||
const auth = req.auth;
|
||||
if (!auth) {
|
||||
throw new UnauthorizedException("Cannot say hello when not authenticated.");
|
||||
throw new UnauthorizedException('Cannot say hello when not authenticated.');
|
||||
}
|
||||
const userData = {
|
||||
id: auth.username,
|
||||
username: auth.username,
|
||||
firstName: auth.firstName ?? '',
|
||||
lastName: auth.lastName ?? ''
|
||||
lastName: auth.lastName ?? '',
|
||||
};
|
||||
if (auth.accountType === "student") {
|
||||
if (auth.accountType === 'student') {
|
||||
await createOrUpdateStudent(userData);
|
||||
logger.debug(`Synchronized student ${userData.username} with IDP`);
|
||||
} else {
|
||||
await createOrUpdateTeacher(userData);
|
||||
logger.debug(`Synchronized teacher ${userData.username} with IDP`);
|
||||
}
|
||||
res.status(200).send({ message: "Welcome!" });
|
||||
res.status(200).send({ message: 'Welcome!' });
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { HasStatusCode } from "./has-status-code";
|
||||
import { HasStatusCode } from './has-status-code';
|
||||
|
||||
/**
|
||||
* Exceptions which are associated with a HTTP error code.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
export interface HasStatusCode {
|
||||
status: number
|
||||
status: number;
|
||||
}
|
||||
export function hasStatusCode(err: unknown): err is HasStatusCode {
|
||||
return typeof err === 'object' && err !== null && 'status' in err && typeof (err as HasStatusCode)?.status === 'number';
|
||||
|
|
|
@ -48,7 +48,7 @@ const idpConfigs = {
|
|||
const verifyJwtToken = expressjwt({
|
||||
secret: async (_: express.Request, token: jwt.Jwt | undefined) => {
|
||||
if (!token?.payload || !(token.payload as JwtPayload).iss) {
|
||||
throw new UnauthorizedException("Invalid token.")
|
||||
throw new UnauthorizedException('Invalid token.');
|
||||
}
|
||||
|
||||
const issuer = (token.payload as JwtPayload).iss;
|
||||
|
|
|
@ -71,7 +71,7 @@ export async function createOrUpdateStudent(userData: StudentDTO): Promise<Stude
|
|||
await getStudentRepository().upsert({
|
||||
username: userData.username,
|
||||
firstName: userData.firstName,
|
||||
lastName: userData.lastName
|
||||
lastName: userData.lastName,
|
||||
});
|
||||
return userData;
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ export async function createOrUpdateTeacher(userData: TeacherDTO): Promise<Teach
|
|||
await getTeacherRepository().upsert({
|
||||
username: userData.username,
|
||||
firstName: userData.firstName,
|
||||
lastName: userData.lastName
|
||||
lastName: userData.lastName,
|
||||
});
|
||||
return userData;
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ const router = createRouter({
|
|||
component: NotFound,
|
||||
meta: { requiresAuth: false },
|
||||
},
|
||||
]
|
||||
],
|
||||
});
|
||||
|
||||
router.beforeEach(async (to, _from, next) => {
|
||||
|
|
|
@ -141,7 +141,7 @@ apiClient.interceptors.request.use(
|
|||
// Registering interceptor to refresh the token when a request failed because it was expired.
|
||||
apiClient.interceptors.response.use(
|
||||
(response) => response,
|
||||
async (error: AxiosError<{ message?: string, inner?: {message?: string} }>) => {
|
||||
async (error: AxiosError<{ message?: string; inner?: { message?: string } }>) => {
|
||||
if (error.response?.status === 401) {
|
||||
// If the user should already be logged in, his token is probably just expired.
|
||||
if (isLoggedIn.value) {
|
||||
|
|
|
@ -15,18 +15,26 @@
|
|||
await auth.handleLoginCallback();
|
||||
await router.replace("/user"); // Redirect to theme page
|
||||
} catch (error) {
|
||||
errorMessage.value = `${ t('loginUnexpectedError') }: ${error}`;
|
||||
errorMessage.value = `${t("loginUnexpectedError")}: ${error}`;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="callback">
|
||||
<div class="callback-loading" v-if="!errorMessage">
|
||||
<div
|
||||
class="callback-loading"
|
||||
v-if="!errorMessage"
|
||||
>
|
||||
<v-progress-circular indeterminate></v-progress-circular>
|
||||
<p>{{ t("callbackLoading") }}</p>
|
||||
</div>
|
||||
<v-alert icon="mdi-alert-circle" type="error" variant="elevated" v-if="errorMessage">
|
||||
<v-alert
|
||||
icon="mdi-alert-circle"
|
||||
type="error"
|
||||
variant="elevated"
|
||||
v-if="errorMessage"
|
||||
>
|
||||
{{ errorMessage }}
|
||||
</v-alert>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue