From 97f14d2757d972f1b416d3d468cd6b1e2788376f Mon Sep 17 00:00:00 2001 From: colenso Date: Fri, 24 Mar 2023 11:58:13 +0530 Subject: [PATCH 1/4] docs: update readme with typescript setup --- README.md | 58 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 73baf454b..56829fde7 100644 --- a/README.md +++ b/README.md @@ -32,16 +32,34 @@ authorization mechanisms__. **Core Feature Guides** -* [The Session Service](#the-session-service) -* [Authenticators](#authenticators) - * [Customizing an Authenticator](#customizing-an-authenticator) - * [Implementing a custom Authenticator](#implementing-a-custom-authenticator) -* [Session Stores](#session-stores) - * [Store Types](#store-types) - * [Implementing a Custom Store](#implementing-a-custom-store) -* [FastBoot](#fastboot) -* [Engines](#engines) -* [Testing](#testing) +- [Ember Simple Auth](#ember-simple-auth) +- [Table of Contents](#table-of-contents) + - [What does it do?](#what-does-it-do) + - [How does it work?](#how-does-it-work) + - [Example App](#example-app) + - [Installation](#installation) + - [TypeScript setup](#typescript-setup) + - [Upgrading from a pre-3.0 release?](#upgrading-from-a-pre-30-release) + - [Upgrading to 4.0 release?](#upgrading-to-40-release) + - [Walkthrough](#walkthrough) + - [The Session Service](#the-session-service) + - [Authenticators](#authenticators) + - [Customizing an Authenticator](#customizing-an-authenticator) + - [Implementing a custom Authenticator](#implementing-a-custom-authenticator) + - [Session Stores](#session-stores) + - [Store Types](#store-types) + - [Adaptive Store](#adaptive-store) + - [`localStorage` Store](#localstorage-store) + - [Cookie Store](#cookie-store) + - [`sessionStorage` Store](#sessionstorage-store) + - [Ephemeral Store](#ephemeral-store) + - [Customizing the Store](#customizing-the-store) + - [Implementing a custom Store](#implementing-a-custom-store) + - [FastBoot](#fastboot) + - [Engines](#engines) + - [Testing](#testing) + - [Other guides](#other-guides) + - [License](#license) **Other Guides** @@ -107,6 +125,26 @@ Installing the library is as easy as: ember install ember-simple-auth ``` +### TypeScript setup +1. Include `ember-cli-flash` typescript defs in the `tsconfig.json` under `paths` like this: + ``` + "paths: { + "ember-simple-auth/*": [ + "node_modules/ember-simple-auth" + ], + } + ``` +2. Import the definition for the type that you need where you need it. For eg: If you have a `session-auth.js` service that uses the `session` service offered by `ember-simple-auth`, you can import the typescript definition for it and use it like this: +
session-auth.js + ``` + import { inject as service } from '@ember/service'; + import Session from 'ember-simple-auth/services/session'; + + export default class SessionAuthService extends Service { + @service declare session: Session<{}> + } + ``` + ### Upgrading from a pre-3.0 release? The 3.0 release of ember-simple-auth removes previously deprecated code, From 509d81fb4b1216f196e44e9b8eaa0b6e6997156d Mon Sep 17 00:00:00 2001 From: colenso Date: Fri, 24 Mar 2023 12:05:58 +0530 Subject: [PATCH 2/4] fix: remove extra bit --- README.md | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 56829fde7..69911fdd4 100644 --- a/README.md +++ b/README.md @@ -32,34 +32,16 @@ authorization mechanisms__. **Core Feature Guides** -- [Ember Simple Auth](#ember-simple-auth) -- [Table of Contents](#table-of-contents) - - [What does it do?](#what-does-it-do) - - [How does it work?](#how-does-it-work) - - [Example App](#example-app) - - [Installation](#installation) - - [TypeScript setup](#typescript-setup) - - [Upgrading from a pre-3.0 release?](#upgrading-from-a-pre-30-release) - - [Upgrading to 4.0 release?](#upgrading-to-40-release) - - [Walkthrough](#walkthrough) - - [The Session Service](#the-session-service) - - [Authenticators](#authenticators) - - [Customizing an Authenticator](#customizing-an-authenticator) - - [Implementing a custom Authenticator](#implementing-a-custom-authenticator) - - [Session Stores](#session-stores) - - [Store Types](#store-types) - - [Adaptive Store](#adaptive-store) - - [`localStorage` Store](#localstorage-store) - - [Cookie Store](#cookie-store) - - [`sessionStorage` Store](#sessionstorage-store) - - [Ephemeral Store](#ephemeral-store) - - [Customizing the Store](#customizing-the-store) - - [Implementing a custom Store](#implementing-a-custom-store) - - [FastBoot](#fastboot) - - [Engines](#engines) - - [Testing](#testing) - - [Other guides](#other-guides) - - [License](#license) +* [The Session Service](#the-session-service) +* [Authenticators](#authenticators) + * [Customizing an Authenticator](#customizing-an-authenticator) + * [Implementing a custom Authenticator](#implementing-a-custom-authenticator) +* [Session Stores](#session-stores) + * [Store Types](#store-types) + * [Implementing a Custom Store](#implementing-a-custom-store) +* [FastBoot](#fastboot) +* [Engines](#engines) +* [Testing](#testing) **Other Guides** From 49b9bae7841df49273e87c828278724d2f177e7f Mon Sep 17 00:00:00 2001 From: colenso Date: Thu, 30 Mar 2023 13:57:34 +0530 Subject: [PATCH 3/4] docs: make suggested changes --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 69911fdd4..f229ca07f 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ ember install ember-simple-auth ``` ### TypeScript setup -1. Include `ember-cli-flash` typescript defs in the `tsconfig.json` under `paths` like this: +1. Include `ember-simple-auth` typescript defs in the `tsconfig.json` under `paths` like this: ``` "paths: { "ember-simple-auth/*": [ @@ -116,11 +116,11 @@ ember install ember-simple-auth ], } ``` -2. Import the definition for the type that you need where you need it. For eg: If you have a `session-auth.js` service that uses the `session` service offered by `ember-simple-auth`, you can import the typescript definition for it and use it like this: +2. Import the definition for the type that you need where you need it. For eg: If you have a `session-auth.ts` service that uses the `session` service offered by `ember-simple-auth`, you can import the typescript definition for it and use it like this:
session-auth.js ``` import { inject as service } from '@ember/service'; - import Session from 'ember-simple-auth/services/session'; + import type Session from 'ember-simple-auth/services/session'; export default class SessionAuthService extends Service { @service declare session: Session<{}> From 1becb06ce0b15f5da8a4d95c38aee764d221434a Mon Sep 17 00:00:00 2001 From: colenso Date: Thu, 6 Apr 2023 13:12:18 +0530 Subject: [PATCH 4/4] fix: add SessionData interface --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f229ca07f..069b26a8b 100644 --- a/README.md +++ b/README.md @@ -122,8 +122,13 @@ ember install ember-simple-auth import { inject as service } from '@ember/service'; import type Session from 'ember-simple-auth/services/session'; + interface SessionData = { + access_token: String, + token_type: String, + } + export default class SessionAuthService extends Service { - @service declare session: Session<{}> + @service declare session: Session } ```