Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

how to add jwt token in angular http request

      tokenType  = 'Bearer ';
      loginUser(data: Student): Observable<any> {
            const url = '/login';
            const header = new HttpHeaders().set('Authorization', this.tokenType + this.cookieService.get('token')); // may be localStorage/sessionStorage
            const headers = { headers: header };
            return this.httpClient.post(this.serverUrl + url, data, headers);
        }
        
        getuserInfo(): Observable<any> {
            const url = '/userinfo';
            const header = new HttpHeaders().set('Authorization', this.tokenType + this.cookieService.get('token')); // may be localStorage/sessionStorage
            const headers = { headers: header };
            return this.httpClient.get(this.serverUrl + url,headers);
        }
        
        submitForm(submission: any): void {
            console.log(submission);
            if (submission && submission.submit) {
                delete submission.submit;
            }
            this.loginService.loginUser(submission)
                .subscribe(result => {
                    console.log(result);
                    this.userinfo();
                }, err => {
                    alert(err);
                });
        }
        
        userinfo() {
            this.loginService.getuserInfo()
            .subscribe(result => {
                console.log(result);
            }, err => {
                alert(err);
            });
        }
Comment

PREVIOUS NEXT
Code Example
Typescript :: angular jasmin mock http response 
Typescript :: count number of set bits in number java 
Typescript :: angular strip html tags pipe 
Typescript :: brackets latex 
Typescript :: typescript remove element from array 
Typescript :: how to fix error 429 too many requests laravel 
Typescript :: mat input formatter tel 
Typescript :: if word contains space detects using jquery 
Typescript :: useState ts 
Typescript :: get elements in list in another list c# 
Typescript :: distance between two points latitude longitude c# 
Typescript :: git status without untracked files 
Typescript :: typescript get class name 
Typescript :: init tsconfig file 
Typescript :: git rebase two commits to one 
Typescript :: bash all arguments except last 
Typescript :: tonumber typescript / Number typescript 
Typescript :: using es6 set in typescript 
Typescript :: check if column exists in dataframe python 
Typescript :: array of objects value repeat check 
Typescript :: rails precompile assets in a directory 
Typescript :: typescript check type 
Typescript :: typescript parameter function type 
Typescript :: how to install downloaded requirements pip with python 
Typescript :: custom link react 
Typescript :: mongoose model enum 
Typescript :: preventing +,-,e from input ts 
Typescript :: js pop object from id 
Typescript :: print query from get_posts wordpress 
Typescript :: graphql server cannot be reached 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =