Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Firebase auth #2385

Merged
merged 38 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2142155
feat(firebase-auth): setup firebase package
mishkolesnikov May 26, 2020
3f06587
feat(firebase-auth): add firebase auth playground
mishkolesnikov May 26, 2020
bb4a27d
feat(firebase-auth): add login/logout
mishkolesnikov May 26, 2020
8e0d6c9
feat(firebase-auth): add refresh token method
mishkolesnikov May 27, 2020
67cff06
feat(firebase-auth): add request password
mishkolesnikov May 27, 2020
a76882e
feat(firebase-auth): add reset password
mishkolesnikov May 27, 2020
0a2c953
feat(firebase-auth): add google strategy
mishkolesnikov May 27, 2020
b514d1e
feat(firebase-auth): add additional params for google strategy
mishkolesnikov May 28, 2020
e4601db
feat(firebase-auth): handle NbAuthIllegalTokenError
mishkolesnikov May 28, 2020
85ee7f6
feat(firebase-auth): add showcase for firebase-google strategy
mishkolesnikov May 28, 2020
720882c
feat(firebase-auth): add base firebase strategy
mishkolesnikov May 29, 2020
a10884b
feat(firebase-auth): add facebook strategy
mishkolesnikov May 29, 2020
9b6a206
feat(firebase-auth): remove facebook and twitter auth from showcase
mishkolesnikov Jun 1, 2020
970acc6
feat(firebase-auth): add default token
mishkolesnikov Jun 1, 2020
b05309d
feat(firebase-auth): add twitter strategy
mishkolesnikov Jun 1, 2020
88acb35
feat(firebase-auth): add documentation
mishkolesnikov Jun 1, 2020
d61abb5
style(firebase-auth): add empty line after license
mishkolesnikov Jun 1, 2020
c9f3dee
chore(firebase-auth): add firebase-auth to the list of firebase packages
mishkolesnikov Jun 1, 2020
0d4074b
chore(firebase-auth): fix lint errors
mishkolesnikov Jun 1, 2020
431bb6d
chore(firebase-auth): feature sponsors on the docs page
mishkolesnikov Jun 1, 2020
9549e9c
fix(firebase-auth): use correct name for rollup global dependency
mishkolesnikov Jun 2, 2020
2df438d
fix(firebase-auth): reexport all entities in public_api
mishkolesnikov Jun 2, 2020
0a0b85d
fix(firebase-auth): fix imports order
mishkolesnikov Jun 2, 2020
a4f9095
fix(firebase-auth): delete unneded comments
mishkolesnikov Jun 2, 2020
617cd40
fix(firebase-auth): fix lint errors
mishkolesnikov Jun 2, 2020
53cdad1
fix(firebase-auth): make reset password method work with confirmPassw…
mishkolesnikov Jun 2, 2020
fb26353
fix(firebase-auth): fix packages build
mishkolesnikov Jun 3, 2020
eaec4e9
Merge branch 'master' into feat/firebase-auth
nnixaa Jun 3, 2020
ae3cd6f
Merge branch 'feat/firebase-auth' of github.com:akveo/nebular into fe…
mishkolesnikov Jun 3, 2020
4ecd850
fix(firebase-auth): add terms and conditions checkbox
mishkolesnikov Jun 3, 2020
7c6c6cd
fix(firebase-auth): fix typos in docs
mishkolesnikov Jun 3, 2020
9dad48b
fix(firebase-auth): remove redundant block from docs page
mishkolesnikov Jun 3, 2020
b3ae5c8
fix(firebase-auth): fix typos
mishkolesnikov Jun 3, 2020
da37cfa
fix(firebase-auth): remove unneeded constructor
mishkolesnikov Jun 3, 2020
aef7b17
fix(firebase-auth): change module prefix
mishkolesnikov Jun 3, 2020
170efff
Merge branch 'master' into feat/firebase-auth
yggg Jun 3, 2020
9a19245
Merge branch 'master' into feat/firebase-auth
yggg Jun 3, 2020
6dd7a19
fix(playground): correct module name
yggg Jun 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(firebase-auth): add documentation
  • Loading branch information
mishkolesnikov committed Jun 1, 2020
commit 88acb3560dea3b405d71bcb96e303372a882ecd0
195 changes: 195 additions & 0 deletions docs/articles/auth/firebase-authentication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
## Firebase authentication with Nebular Auth
@nebualar/firebase-auth allows authentication in firebase applications with nebular/auth.
The package provides the following strategies:
- NbFirebasePasswordStrategy - authentication with email/password
- NbFirebaseGoogleStrategy - authentication with google accounts
- NbFirebaseFacebookStrategy - authentication with facebook accounts
- NbFirebaseTwitteStrategy - authentication with twitter accounts

## Installation

<div class="note note-info">
<div class="note-title">Note</div>
<div class="note-body">
The package connects firebase auth with nebular/auth so you need `firebase` and `@angular/fire` installed
and configured for your application. For more instructions please see [@angular/fire docs](https://github.com/akveo/nebular/tree/master/src/playground/without-layout/azure).
Also make sure you import AngularFireAuthModule.
</div>
</div>


Install Nebular Auth and Nebular Firebase Auth.

```sh
npm i @nebular/eva-icons firebase @angular\fire
mishkolesnikov marked this conversation as resolved.
Show resolved Hide resolved
```

Import the NbAuthModule with some firebase strategies, in that example we use NbFirebasePasswordStrategy.

```ts
import { NbAuthModule } from '@nebular/auth';
import { NbFirebasePasswordStrategy } from '@nebular/firebase-auth';


@NgModule({
imports: [
// ...

NbAuthModule.forRoot({
strategies: [
NbFirebasePasswordStrategy.setup({
name: 'password',
}),
],
forms: {},
}),
],
});
```
<hr>

## Authentication with email and password

Nebular Firebase Auth provides NbFirebasePassword strategy for authentication with email and password.

Strategy settings:
<div class="note note-info">
<div class="note-title">Note</div>
<div class="note-body">
There is no need to copy over the whole object to change the settings you need.
Also, this.getOption call won't work outside of the default options declaration (which is inside of the NbPasswordAuthStrategy class),
so you have to replace it with a custom helper function if you need it.
</div>
</div>

```ts
export class NbFirebasePasswordStrategyOptions extends NbAuthStrategyOptions {
name: string;
token = {
class: NbAuthJWTToken,
};
register?: boolean | NbPasswordStrategyModule = {
redirect: {
success: '/',
failure: null,
},
defaultErrors: ['Something went wrong, please try again.'],
defaultMessages: ['You have been successfully registered.'],
};
login?: boolean | NbPasswordStrategyModule = {
redirect: {
success: '/',
failure: null,
},
defaultErrors: ['Login/Email combination is not correct, please try again.'],
defaultMessages: ['You have been successfully logged in.'],
};
logout?: boolean | NbPasswordStrategyModule = {
redirect: {
success: '/',
failure: null,
},
defaultErrors: ['Something went wrong, please try again.'],
defaultMessages: ['You have been successfully logged out.'],
};
refreshToken?: boolean | NbPasswordStrategyModule = {
redirect: {
success: null,
failure: null,
},
defaultErrors: ['Something went wrong, please try again.'],
defaultMessages: ['Your token has been successfully refreshed.'],
};
requestPassword?: boolean | NbPasswordStrategyModule = {
redirect: {
success: '/',
failure: null,
},
defaultErrors: ['Something went wrong, please try again.'],
defaultMessages: ['Reset password instructions have been sent to your email.'],
};
resetPassword?: boolean | NbPasswordStrategyModule = {
redirect: {
success: '/',
failure: null,
},
defaultErrors: ['Something went wrong, please try again.'],
defaultMessages: ['Your password has been successfully changed.'],
};
errors?: NbPasswordStrategyMessage = {
key: 'message',
getter: (module: string, res, options: NbFirebasePasswordStrategyOptions) => getDeepFromObject(
res,
options.errors.key,
options[module].defaultErrors,
),
};
messages?: NbPasswordStrategyMessage = {
key: 'messages',
getter: (module: string, res, options: NbFirebasePasswordStrategyOptions) => getDeepFromObject(
res.body,
options.messages.key,
options[module].defaultMessages,
),
};
}
```
<hr>

## Social Authentication providers

Nebular Firebase Auth for now provides strategies for authentication with Google, Facebook and Twitter.
These strategies share the same settings structure and default settings value.

Strategies settings:

<div class="note note-info">
mishkolesnikov marked this conversation as resolved.
Show resolved Hide resolved
<div class="note-title">Note</div>
<div class="note-body">
There is no need to copy over the whole object to change the settings you need.
Also, this.getOption call won't work outside of the default options declaration (which is inside of the NbPasswordAuthStrategy class),
so you have to replace it with a custom helper function if you need it.
</div>
</div>

```ts
export class NbFirebaseIdentityProviderStrategyOptions extends NbAuthStrategyOptions {
name: string;
logout?: boolean | NbPasswordStrategyModule = {
redirect: {
success: '/',
failure: null,
},
defaultErrors: ['Something went wrong, please try again.'],
defaultMessages: ['You have been successfully logged out.'],
};
authenticate?: boolean | NbPasswordStrategyModule = {
redirect: {
success: '/',
failure: null,
},
defaultErrors: ['Something went wrong, please try again.'],
defaultMessages: ['You have been successfully authenticated.'],
};
errors?: NbPasswordStrategyMessage = {
key: 'message',
getter: (module: string, res, options: NbFirebaseIdentityProviderStrategyOptions) => options[module].defaultErrors,
};
messages?: NbPasswordStrategyMessage = {
key: 'message',
getter: (module: string, res, options: NbFirebaseIdentityProviderStrategyOptions) => options[module].defaultMessages,
};
scopes?: string[] = [];
customParameters?: { [key: string]: string } = {};
}
};
```
<hr>

## Complete example

A complete code example could be found on [GitHub](https://github.com/akveo/nebular/tree/master/src/playground/with-layout/firebase).

And here the playground examples available to play around with
- [Firebase Nebular Password Example](/example/firebase/password-showcase)
- [Firebase Nebular Social Authentication Providers Example](/example/firebase/social-auth-showcase)
2 changes: 2 additions & 0 deletions docs/articles/getting-started/what-is-nebular.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Nebular modules are distributed as separated `npm` packages:
- Authentication components (login/register/reset password/restore password).
- Multiple configurable authentication Strategies (backend connectors).
- Helpers for token management (storing, passing with HTTP requests, etc).
- Nebular Auth for Firebase `@nebular/firebase-auth
- module for authentication in firebase applications with nebular/auth
- Nebular Security `@nebular/security`
- roles and permissions management.
- Nebular Moment `@nebular/moment`
Expand Down
16 changes: 16 additions & 0 deletions docs/structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,22 @@ export const structure = [
},
],
},
{
type: 'page',
name: 'Firebase Authentication',
children: [
{
type: 'block',
block: 'markdown',
source: 'auth/firebase-authentication.md',
},
{
type: 'block',
block: 'component',
source: 'NbPasswordAuthStrategy',
mishkolesnikov marked this conversation as resolved.
Show resolved Hide resolved
},
],
},
{
type: 'page',
name: 'NbAuthService',
Expand Down
3 changes: 2 additions & 1 deletion docs/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"@nebular/theme": ["../src/framework/theme/public_api.ts"],
"@nebular/auth": ["../src/framework/auth/public_api.ts"],
"@nebular/security": ["../src/framework/security/public_api.ts"],
"@nebular/eva-icons": ["../src/framework/eva-icons/public_api.ts"]
"@nebular/eva-icons": ["../src/framework/eva-icons/public_api.ts"],
"@nebular/firebase-auth": ["../src/framework/firebase-auth/public_api.ts"]
}
},
"files": [
Expand Down