https://github.com/streamich/client-passport
Authentication for single-page apps
https://github.com/streamich/client-passport
Last synced: 11 months ago
JSON representation
Authentication for single-page apps
- Host: GitHub
- URL: https://github.com/streamich/client-passport
- Owner: streamich
- License: unlicense
- Created: 2018-11-25T13:27:56.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T05:09:31.000Z (over 2 years ago)
- Last Synced: 2025-08-09T03:23:23.864Z (11 months ago)
- Language: TypeScript
- Homepage:
- Size: 312 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# client-passport
Universal authentication for client-side apps, supported providers:
- [x] Google Sign-in for Websites
- [x] Facebook SDK
## Usage
Create `authenticator` instance.
```js
import {passport} from 'client-passport';
import {loader as facebookLoader} from 'client-passport/lib/providers/facebook';
const authenticator = passport({
providers: {
google: async () => ({
loader: (await import('client-passport/lib/providers/google')).loader,
options: {
client_id: 'xxxxxxxxxx-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyy.apps.googleusercontent.com',
},
}),
facebook: () => ({
loader: facebookLoader,
options: {
appId: '00000000000000',
autoLogAppEvents: true,
xfbml: true,
version: 'v5.0',
}
}),
}
});
```
Subscribe to `user` changes. Every time user logs in this callback is called. When
user logs out, `user` is set to `null`.
```js
authenticator.onchange = (user) => {
//
};
```
Sign-in with selected provider.
```js
user = await authenticator.signIn('google');
user = await authenticator.signIn('facebook');
```
Sign-out.
```js
await authenticator.signOut();
```
## License
[Unlicense](LICENSE) — public domain.