mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender-pwa.git
synced 2026-01-18 17:22:26 +01:00
feat:#4 extracted token regex test
This commit is contained in:
19
frontend/src/helpers/token.ts
Normal file
19
frontend/src/helpers/token.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
const tokenRegex = /^[a-z0-9]{15}$/;
|
||||
const tokenUriRegex = /[?&]token=([a-z0-9]{15})(?:&|$)/;
|
||||
|
||||
export const isToken = (token: string): boolean => {
|
||||
return tokenRegex.test(token) || tokenUriRegex.test(token);
|
||||
};
|
||||
|
||||
export function extractToken(token: string): string {
|
||||
if (tokenRegex.test(token)) {
|
||||
return token;
|
||||
}
|
||||
|
||||
const match = tokenUriRegex.exec(token);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
|
||||
throw new Error("Invalid token");
|
||||
}
|
||||
Reference in New Issue
Block a user