File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ export const TLD: Record<string, string> = {
55} ;
66
77export const NEETO_URL_COMPONENT_REGEX = / n e e t o ( \w + ) / ;
8+ export const NEETO_URL_PREFIX_REGEX = / ^ ( h t t p s ? : \/ \/ ) ? ( w w w \. ) ? [ \w - ] + \. / ;
89
910export const CLIENT_APPS = {
1011 cal : "Cal" ,
Original file line number Diff line number Diff line change 11import jwt from "jsonwebtoken" ;
2- import { getClientAppName , getLoginUri , SearchParams } from "./utils.js" ;
2+ import {
3+ getClientAppName ,
4+ getLoginUri ,
5+ getRedirectUri ,
6+ SearchParams ,
7+ } from "./utils.js" ;
38
49interface Options {
510 email : string ;
@@ -48,7 +53,7 @@ class NeetoJWT {
4853
4954 const searchParams : SearchParams = {
5055 jwt : this . generateJWT ( ) ,
51- redirect_uri : encodeURI ( redirectUri ) ,
56+ redirect_uri : getRedirectUri ( redirectUri ) ,
5257 client_app_name : getClientAppName ( redirectUri ) ,
5358 } ;
5459
Original file line number Diff line number Diff line change 1- import { CLIENT_APPS , NEETO_URL_COMPONENT_REGEX , TLD } from "./constants.js" ;
1+ import {
2+ CLIENT_APPS ,
3+ NEETO_URL_COMPONENT_REGEX ,
4+ NEETO_URL_PREFIX_REGEX ,
5+ TLD ,
6+ } from "./constants.js" ;
27
38export type SearchParams = {
49 jwt : string ;
@@ -29,3 +34,13 @@ export const getClientAppName = (redirectUri: string) => {
2934
3035 return "Cal" ;
3136} ;
37+
38+ export const getRedirectUri = ( redirectUri : string ) => {
39+ const match = redirectUri . match ( NEETO_URL_PREFIX_REGEX ) ;
40+
41+ if ( match ) {
42+ return encodeURI ( redirectUri . replace ( NEETO_URL_PREFIX_REGEX , "" ) ) ;
43+ }
44+
45+ return encodeURI ( getTopLevelDomain ( ) ) ;
46+ } ;
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ describe("NeetoJWT", () => {
5353 expect ( loginUrl ) . toContain ( "https://spinkart.neetoauth.com/users/auth/jwt" ) ;
5454 expect ( loginUrl ) . toContain ( `jwt=` ) ;
5555 expect ( loginUrl ) . toContain (
56- `redirect_uri=${ encodeURIComponent ( redirectUri ) } `
56+ `redirect_uri=${ encodeURIComponent ( "neetocal.com/admin" ) } `
5757 ) ;
5858 expect ( loginUrl ) . toContain ( `client_app_name=Cal` ) ;
5959 } ) ;
You can’t perform that action at this time.
0 commit comments