@environments/environment#environment TypeScript Examples
The following examples show how to use
@environments/environment#environment.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: authentication.service.ts From angular-10-basic-authentication-example with MIT License | 6 votes |
login(username: string, password: string) {
return this.http.post<any>(`${environment.apiUrl}/users/authenticate`, { username, password })
.pipe(map(user => {
// store user details and basic auth credentials in local storage to keep user logged in between page refreshes
user.authdata = window.btoa(username + ':' + password);
localStorage.setItem('user', JSON.stringify(user));
this.userSubject.next(user);
return user;
}));
}
Example #2
Source File: authentication.service.ts From angular-10-role-based-authorization-example with MIT License | 6 votes |
login(username: string, password: string) {
return this.http.post<any>(`${environment.apiUrl}/users/authenticate`, { username, password })
.pipe(map(user => {
// store user details and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem('user', JSON.stringify(user));
this.userSubject.next(user);
return user;
}));
}
Example #3
Source File: jwt.interceptor.ts From angular-10-role-based-authorization-example with MIT License | 6 votes |
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// add auth header with jwt if user is logged in and request is to api url
const user = this.authenticationService.userValue;
const isLoggedIn = user && user.token;
const isApiUrl = request.url.startsWith(environment.apiUrl);
if (isLoggedIn && isApiUrl) {
request = request.clone({
setHeaders: {
Authorization: `Bearer ${user.token}`
}
});
}
return next.handle(request);
}
Example #4
Source File: account.service.ts From angular-10-registration-login-example with MIT License | 6 votes |
delete(id: string) {
return this.http.delete(`${environment.apiUrl}/users/${id}`)
.pipe(map(x => {
// auto logout if the logged in user deleted their own record
if (id == this.userValue.id) {
this.logout();
}
return x;
}));
}
Example #5
Source File: account.service.ts From angular-10-registration-login-example with MIT License | 6 votes |
update(id, params) {
return this.http.put(`${environment.apiUrl}/users/${id}`, params)
.pipe(map(x => {
// update stored user if the logged in user updated their own record
if (id == this.userValue.id) {
// update local storage
const user = { ...this.userValue, ...params };
localStorage.setItem('user', JSON.stringify(user));
// publish updated user to subscribers
this.userSubject.next(user);
}
return x;
}));
}
Example #6
Source File: jwt.interceptor.ts From angular-10-signup-verification-boilerplate with MIT License | 6 votes |
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// add auth header with jwt if account is logged in and request is to the api url
const account = this.accountService.accountValue;
const isLoggedIn = account && account.jwtToken;
const isApiUrl = request.url.startsWith(environment.apiUrl);
if (isLoggedIn && isApiUrl) {
request = request.clone({
setHeaders: { Authorization: `Bearer ${account.jwtToken}` }
});
}
return next.handle(request);
}
Example #7
Source File: account.service.ts From angular-10-registration-login-example with MIT License | 6 votes |
login(username, password) {
return this.http.post<User>(`${environment.apiUrl}/users/authenticate`, { username, password })
.pipe(map(user => {
// store user details and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem('user', JSON.stringify(user));
this.userSubject.next(user);
return user;
}));
}
Example #8
Source File: jwt.interceptor.ts From angular-10-registration-login-example with MIT License | 6 votes |
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// add auth header with jwt if user is logged in and request is to the api url
const user = this.accountService.userValue;
const isLoggedIn = user && user.token;
const isApiUrl = request.url.startsWith(environment.apiUrl);
if (isLoggedIn && isApiUrl) {
request = request.clone({
setHeaders: {
Authorization: `Bearer ${user.token}`
}
});
}
return next.handle(request);
}
Example #9
Source File: seo.service.ts From scully-plugins with MIT License | 6 votes |
generateTags(config: SeoConfig = {}) {
config.keywords
? (config.keywords = [...environment.keywords, ...config.keywords])
: (config.keywords = environment.keywords);
config = {
title: environment.title,
description: environment.description,
image: this.absoluteImageUrl(environment.featureImage),
route: '',
...config
};
this.title.setTitle(config.title);
this.meta.updateTag({ name: 'description', content: config.description });
this.meta.updateTag({ name: 'robots', content: 'index, follow' });
this.meta.updateTag({
name: 'keywords',
content: config.keywords.join(', ')
});
this.twitterCard(config);
}
Example #10
Source File: jwt.interceptor.ts From angular-10-jwt-refresh-tokens with MIT License | 6 votes |
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// add auth header with jwt if user is logged in and request is to the api url
const user = this.authenticationService.userValue;
const isLoggedIn = user && user.jwtToken;
const isApiUrl = request.url.startsWith(environment.apiUrl);
if (isLoggedIn && isApiUrl) {
request = request.clone({
setHeaders: { Authorization: `Bearer ${user.jwtToken}` }
});
}
return next.handle(request);
}
Example #11
Source File: authentication.service.ts From angular-10-jwt-authentication-example with MIT License | 6 votes |
login(username: string, password: string) {
return this.http.post<any>(`${environment.apiUrl}/users/authenticate`, { username, password })
.pipe(map(user => {
// store user details and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem('currentUser', JSON.stringify(user));
this.currentUserSubject.next(user);
return user;
}));
}
Example #12
Source File: jwt.interceptor.ts From angular-10-jwt-authentication-example with MIT License | 6 votes |
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// add auth header with jwt if user is logged in and request is to the api url
const currentUser = this.authenticationService.currentUserValue;
const isLoggedIn = currentUser && currentUser.token;
const isApiUrl = request.url.startsWith(environment.apiUrl);
if (isLoggedIn && isApiUrl) {
request = request.clone({
setHeaders: {
Authorization: `Bearer ${currentUser.token}`
}
});
}
return next.handle(request);
}
Example #13
Source File: jwt.interceptor.ts From angular-10-facebook-login-example with MIT License | 6 votes |
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// add auth header with jwt if account is logged in and request is to the api url
const account = this.accountService.accountValue;
const isLoggedIn = account?.token;
const isApiUrl = request.url.startsWith(environment.apiUrl);
if (isLoggedIn && isApiUrl) {
request = request.clone({
setHeaders: { Authorization: `Bearer ${account.token}` }
});
}
return next.handle(request);
}
Example #14
Source File: app.initializer.ts From angular-10-facebook-login-example with MIT License | 6 votes |
export function appInitializer(accountService: AccountService) {
return () => new Promise(resolve => {
// wait for facebook sdk to initialize before starting the angular app
window['fbAsyncInit'] = function () {
FB.init({
appId: environment.facebookAppId,
cookie: true,
xfbml: true,
version: 'v8.0'
});
// auto authenticate with the api if already logged in with facebook
FB.getLoginStatus(({authResponse}) => {
if (authResponse) {
accountService.apiAuthenticate(authResponse.accessToken)
.subscribe()
.add(resolve);
} else {
resolve();
}
});
};
// load facebook sdk script
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) { return; }
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
});
}
Example #15
Source File: basic-auth.interceptor.ts From angular-10-basic-authentication-example with MIT License | 6 votes |
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// add header with basic auth credentials if user is logged in and request is to the api url
const user = this.authenticationService.userValue;
const isLoggedIn = user && user.authdata;
const isApiUrl = request.url.startsWith(environment.apiUrl);
if (isLoggedIn && isApiUrl) {
request = request.clone({
setHeaders: {
Authorization: `Basic ${user.authdata}`
}
});
}
return next.handle(request);
}
Example #16
Source File: user.service.ts From angular-master-details-crud-example with MIT License | 5 votes |
baseUrl = `${environment.apiUrl}/users`
Example #17
Source File: user.service.ts From angular-11-crud-example with MIT License | 5 votes |
baseUrl = `${environment.apiUrl}/users`
Example #18
Source File: account.service.ts From angular-10-signup-verification-boilerplate with MIT License | 5 votes |
baseUrl = `${environment.apiUrl}/accounts`
Example #19
Source File: seo.service.ts From scully-plugins with MIT License | 5 votes |
private absoluteImageUrl(image: string) {
return `${environment.url}/${image}`;
}
Example #20
Source File: user.service.ts From angular-10-role-based-authorization-example with MIT License | 5 votes |
getById(id: number) {
return this.http.get<User>(`${environment.apiUrl}/users/${id}`);
}
Example #21
Source File: products.service.ts From mini-projects-2021 with MIT License | 5 votes |
baseUrl = environment.productsWebApiUrl
Example #22
Source File: user.service.ts From angular-10-role-based-authorization-example with MIT License | 5 votes |
getAll() {
return this.http.get<User[]>(`${environment.apiUrl}/users`);
}
Example #23
Source File: account.service.ts From angular-10-registration-login-example with MIT License | 5 votes |
getById(id: string) {
return this.http.get<User>(`${environment.apiUrl}/users/${id}`);
}
Example #24
Source File: account.service.ts From angular-10-registration-login-example with MIT License | 5 votes |
getAll() {
return this.http.get<User[]>(`${environment.apiUrl}/users`);
}
Example #25
Source File: account.service.ts From angular-10-registration-login-example with MIT License | 5 votes |
register(user: User) {
return this.http.post(`${environment.apiUrl}/users/register`, user);
}
Example #26
Source File: authentication.service.ts From angular-10-jwt-refresh-tokens with MIT License | 5 votes |
refreshToken() {
return this.http.post<any>(`${environment.apiUrl}/users/refresh-token`, {}, { withCredentials: true })
.pipe(map((user) => {
this.userSubject.next(user);
this.startRefreshTokenTimer();
return user;
}));
}
Example #27
Source File: authentication.service.ts From angular-10-jwt-refresh-tokens with MIT License | 5 votes |
logout() {
this.http.post<any>(`${environment.apiUrl}/users/revoke-token`, {}, { withCredentials: true }).subscribe();
this.stopRefreshTokenTimer();
this.userSubject.next(null);
this.router.navigate(['/login']);
}
Example #28
Source File: authentication.service.ts From angular-10-jwt-refresh-tokens with MIT License | 5 votes |
login(username: string, password: string) {
return this.http.post<any>(`${environment.apiUrl}/users/authenticate`, { username, password }, { withCredentials: true })
.pipe(map(user => {
this.userSubject.next(user);
this.startRefreshTokenTimer();
return user;
}));
}
Example #29
Source File: account.service.ts From angular-10-facebook-login-example with MIT License | 5 votes |
baseUrl = `${environment.apiUrl}/accounts`