Skip to content

Commit 6e7db29

Browse files
committed
Added currentAuthData getter
1 parent 0126b3c commit 6e7db29

File tree

4 files changed

+65
-25
lines changed

4 files changed

+65
-25
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Log
22

3+
## v0.1.16
4+
**Featues:**
5+
- Added `userSignedIn()` method
6+
- Added `currentAuthData` getter
7+
**Bugfixes:**
8+
- Fix `CanActivate` on page reload
9+
310
## v0.1.15
411
**Featues:**
512
- Added global options for setting custom global headers

README.md

+53-24
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@ The repository can be found [here](https://github.com/neroniaky/angular2-token-e
3030
- [`.updatePassword()`](#updatepassword)
3131
- [`.resetPassword()`](#resetpassword)
3232
- [HTTP Service Wrapper](#http-service-wrapper)
33-
- [`.sendHttpRequest()`](#sendhttprequest)
3433
- [Multiple User Types](#multiple-user-types)
3534
- [Route Guards](#route-guards)
36-
- [Testing](#testing)
35+
- [Advanced Usage](#advanced-usage)
36+
- [`.sendHttpRequest()`](#sendhttprequest)
37+
- [`.userSignedIn()`](#usersignedin)
38+
- [`.currentUserType`](#currentusertype)
39+
- [`.currentUserData`](#currentuserdata)
40+
- [`.currentAuthData`](#currentauthdata)
3741
- [Development](#development)
38-
- [Credits](#credits)
39-
- [License](#license)
42+
- [Testing](#testing)
43+
- [Credits](#credits)
44+
- [License](#license)
4045

4146
## Installation
4247
1. Install Angular2-Token via NPM with
@@ -263,21 +268,6 @@ this._tokenService.get('my-resource/1').map(res => res.json()).subscribe(
263268
);
264269
```
265270
266-
### .sendHttpRequest()
267-
More customized requests can be send with the `.sendHttpRequest()`-function. It accepts the RequestOptions-Class.
268-
More information can be found in the Angular2 API Reference [here](https://angular.io/docs/ts/latest/api/http/index/RequestOptions-class.html).
269-
270-
`sendHttpRequest(options: RequestOptions): Observable<Response>`
271-
272-
#### Example:
273-
```javascript
274-
this.sendHttpRequest(new RequestOptions({
275-
method: RequestMethod.Post,
276-
url: 'my-resource/1',
277-
data: mydata
278-
}));
279-
```
280-
281271
## Multiple User Types
282272
An array of `UserType` can be passed in `Angular2TokenOptions` during `init()`.
283273
The user type is selected during sign in and persists until sign out.
@@ -320,11 +310,45 @@ const routerConfig: Routes = [
320310
];
321311
```
322312
323-
## Testing
324-
```bash
325-
npm test
313+
## Advanced Usage
314+
More advanced methods can be used if a higher degree of customization is required.
315+
316+
### .sendHttpRequest()
317+
More customized requests can be send with the `.sendHttpRequest()`-function. It accepts the RequestOptions-Class.
318+
More information can be found in the Angular2 API Reference [here](https://angular.io/docs/ts/latest/api/http/index/RequestOptions-class.html).
319+
320+
`sendHttpRequest(options: RequestOptions): Observable<Response>`
321+
322+
#### Example:
323+
```javascript
324+
this.sendHttpRequest(new RequestOptions({
325+
method: RequestMethod.Post,
326+
url: 'my-resource/1',
327+
data: mydata
328+
}));
326329
```
327330
331+
### .userSignedIn()
332+
Returns `true` if a user is signed in. It does not distinguish between user types.
333+
334+
`userSignedIn(): boolean`
335+
336+
### .currentUserType
337+
Returns current user type as string like specified in the options.
338+
339+
`get currentUserType(): string`
340+
341+
### .currentUserData
342+
Returns current user data as returned by devise token auth.
343+
This variable is `null` after page reload until the `.validateToken()` call is answerd by the backend.
344+
345+
`get currentUserData(): UserData`
346+
347+
### .currentAuthData
348+
Returns current authentication data which are used to set auth headers.
349+
350+
`get currentAuthData(): AuthData`
351+
328352
## Development
329353
If the package is installed from Github specified in the package.json, you need to build the package locally.
330354
@@ -334,8 +358,13 @@ npm install
334358
npm run build
335359
```
336360
337-
## Credits
361+
### Testing
362+
```bash
363+
npm test
364+
```
365+
366+
### Credits
338367
Test config files based on [Angular2 Webpack Starter](https://github.com/AngularClass/angular2-webpack-starter) by AngularClass
339368
340-
## License
369+
### License
341370
The MIT License (see the [LICENSE](https://github.com/neroniaky/angular2-token/blob/master/LICENSE) file for the full text)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular2-token",
3-
"version": "0.1.15",
3+
"version": "0.1.16",
44
"description": "Angular2 service for token based authentication",
55
"main": "./angular2-token.js",
66
"typings": "./angular2-token.d.ts",

src/angular2-token.service.ts

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export class Angular2TokenService implements CanActivate {
3333
return this._currentUserData;
3434
}
3535

36+
get currentAuthData(): AuthData {
37+
return this._currentAuthData;
38+
}
39+
3640
private _options: Angular2TokenOptions;
3741
private _currentUserType: UserType;
3842
private _currentAuthData: AuthData;

0 commit comments

Comments
 (0)