1- import { defaultFetcher , type Fetcher , findValueBetween , getCookiesFromResponse } from "@literate.ink/utilities" ;
1+ import {
2+ defaultFetcher ,
3+ type Fetcher ,
4+ findValueBetween ,
5+ getCookiesFromResponse
6+ } from "@literate.ink/utilities" ;
27import { HOST } from "~cas/constants" ;
38
4- const retrieveLoginToken = async ( fetcher : Fetcher , retries = 0 ) : Promise < string > => {
9+ const retrieveLoginToken = async (
10+ fetcher : Fetcher ,
11+ retries = 0
12+ ) : Promise < string > => {
513 const response = await fetcher ( {
614 url : new URL ( HOST )
715 } ) ;
816
917 // find the token that allows to send the login request.
10- const token = findValueBetween ( response . content , "name=\"token\" value=\"" , "\" />" ) ;
18+ const token = findValueBetween (
19+ response . content ,
20+ "name=\"token\" value=\"" ,
21+ "\" />"
22+ ) ;
1123
1224 if ( ! token ) {
1325 // we retry 5 times before throwing the actual error.
@@ -25,7 +37,11 @@ const retrieveLoginToken = async (fetcher: Fetcher, retries = 0): Promise<string
2537 * authenticates to `https://cas.unilim.fr` using the given `username` and `password`.
2638 * @returns the `lemonldap` cookie that is a token for further authenticated requests.
2739 */
28- export const login = async ( username : string , password : string , fetcher : Fetcher = defaultFetcher ) : Promise < string > => {
40+ export const login = async (
41+ username : string ,
42+ password : string ,
43+ fetcher : Fetcher = defaultFetcher
44+ ) : Promise < string > => {
2945 const token = await retrieveLoginToken ( fetcher ) ;
3046
3147 // send the login request.
@@ -50,8 +66,7 @@ export const login = async (username: string, password: string, fetcher: Fetcher
5066 const cookies = getCookiesFromResponse ( response ) ;
5167 const lemonCookie = cookies [ 0 ] . split ( "=" ) [ 1 ] ;
5268
53- if ( ! lemonCookie )
54- throw new Error ( "bad authentication" ) ;
69+ if ( ! lemonCookie ) throw new Error ( "bad authentication" ) ;
5570
5671 return lemonCookie ;
5772} ;
0 commit comments