Skip to content

Commit

Permalink
Added currentAuthData getter
Browse files Browse the repository at this point in the history
  • Loading branch information
neroniaky committed Oct 8, 2016
1 parent 0126b3c commit 6e7db29
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 25 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## v0.1.16
**Featues:**
- Added `userSignedIn()` method
- Added `currentAuthData` getter
**Bugfixes:**
- Fix `CanActivate` on page reload

## v0.1.15
**Featues:**
- Added global options for setting custom global headers
Expand Down
77 changes: 53 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ The repository can be found [here](https://github.com/neroniaky/angular2-token-e
- [`.updatePassword()`](#updatepassword)
- [`.resetPassword()`](#resetpassword)
- [HTTP Service Wrapper](#http-service-wrapper)
- [`.sendHttpRequest()`](#sendhttprequest)
- [Multiple User Types](#multiple-user-types)
- [Route Guards](#route-guards)
- [Testing](#testing)
- [Advanced Usage](#advanced-usage)
- [`.sendHttpRequest()`](#sendhttprequest)
- [`.userSignedIn()`](#usersignedin)
- [`.currentUserType`](#currentusertype)
- [`.currentUserData`](#currentuserdata)
- [`.currentAuthData`](#currentauthdata)
- [Development](#development)
- [Credits](#credits)
- [License](#license)
- [Testing](#testing)
- [Credits](#credits)
- [License](#license)

## Installation
1. Install Angular2-Token via NPM with
Expand Down Expand Up @@ -263,21 +268,6 @@ this._tokenService.get('my-resource/1').map(res => res.json()).subscribe(
);
```
### .sendHttpRequest()
More customized requests can be send with the `.sendHttpRequest()`-function. It accepts the RequestOptions-Class.
More information can be found in the Angular2 API Reference [here](https://angular.io/docs/ts/latest/api/http/index/RequestOptions-class.html).
`sendHttpRequest(options: RequestOptions): Observable<Response>`
#### Example:
```javascript
this.sendHttpRequest(new RequestOptions({
method: RequestMethod.Post,
url: 'my-resource/1',
data: mydata
}));
```
## Multiple User Types
An array of `UserType` can be passed in `Angular2TokenOptions` during `init()`.
The user type is selected during sign in and persists until sign out.
Expand Down Expand Up @@ -320,11 +310,45 @@ const routerConfig: Routes = [
];
```
## Testing
```bash
npm test
## Advanced Usage
More advanced methods can be used if a higher degree of customization is required.
### .sendHttpRequest()
More customized requests can be send with the `.sendHttpRequest()`-function. It accepts the RequestOptions-Class.
More information can be found in the Angular2 API Reference [here](https://angular.io/docs/ts/latest/api/http/index/RequestOptions-class.html).
`sendHttpRequest(options: RequestOptions): Observable<Response>`
#### Example:
```javascript
this.sendHttpRequest(new RequestOptions({
method: RequestMethod.Post,
url: 'my-resource/1',
data: mydata
}));
```
### .userSignedIn()
Returns `true` if a user is signed in. It does not distinguish between user types.
`userSignedIn(): boolean`
### .currentUserType
Returns current user type as string like specified in the options.
`get currentUserType(): string`
### .currentUserData
Returns current user data as returned by devise token auth.
This variable is `null` after page reload until the `.validateToken()` call is answerd by the backend.
`get currentUserData(): UserData`
### .currentAuthData
Returns current authentication data which are used to set auth headers.
`get currentAuthData(): AuthData`
## Development
If the package is installed from Github specified in the package.json, you need to build the package locally.
Expand All @@ -334,8 +358,13 @@ npm install
npm run build
```
## Credits
### Testing
```bash
npm test
```
### Credits
Test config files based on [Angular2 Webpack Starter](https://github.com/AngularClass/angular2-webpack-starter) by AngularClass
## License
### License
The MIT License (see the [LICENSE](https://github.com/neroniaky/angular2-token/blob/master/LICENSE) file for the full text)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular2-token",
"version": "0.1.15",
"version": "0.1.16",
"description": "Angular2 service for token based authentication",
"main": "./angular2-token.js",
"typings": "./angular2-token.d.ts",
Expand Down
4 changes: 4 additions & 0 deletions src/angular2-token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export class Angular2TokenService implements CanActivate {
return this._currentUserData;
}

get currentAuthData(): AuthData {
return this._currentAuthData;
}

private _options: Angular2TokenOptions;
private _currentUserType: UserType;
private _currentAuthData: AuthData;
Expand Down

0 comments on commit 6e7db29

Please sign in to comment.