import { URL } from 'url' ; import Client from '../client' ; import { hostname } from 'os' ; import { getTitleName } from '../pkg-name' ; import { LoginResultSuccess } from './types' ; export default function verify ( client , verificationToken , email , provider , ssoUserId ? ) { const url = new URL ( '/registration/verify' , client . apiUrl ) ; url . searchParams . set ( 'token' , verificationToken ) ; if ( email ) { url . searchParams . set ( 'email' , email ) ; } if ( ! client . authConfig . token ) { const hyphens = new RegExp ( '-' , 'g' ) ; const host = hostname ( ) . replace ( hyphens , ' ' ) . replace ( '.local' , '' ) ; const tokenName = `${ getTitleName ( ) } CLI on ${ host } via ${ provider }` ; url . searchParams . set ( 'tokenName' , tokenName ) ; } if ( ssoUserId ) { url . searchParams . set ( 'ssoUserId' , ssoUserId ) ; } return client . fetch < LoginResultSuccess > ( url . href , { useCurrentTeam : false } ) ; }