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

[pull] master from mainmatter:master #108

Merged
merged 9 commits into from
Dec 29, 2024
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ authorization mechanisms__.

* [Managing a current User](guides/managing-current-user.md)
* [GitHub authorization with torii](guides/auth-torii-with-github.md)
* [Upgrading to v7](guides/upgrade-to-v7.md)
* [Upgrading to v4](guides/upgrade-to-v4.md)
* [Upgrading to v3](guides/upgrade-to-v3.md)

Expand Down Expand Up @@ -128,7 +129,23 @@ as well as prepare yourself for v5 release which will make it **required**.

## Walkthrough

Once the library is installed, __the session service can be injected wherever
Once the library is installed, import a session service and a session-store inside your application__.

### Add `app/services/session.js` or `app/services/session.ts`
```js
import Service from 'ember-simple-auth/services/session';

export default class SessionService extends Service {}
```

### Add `app/session-stores/application.js` or `app/session-stores/application.ts`
```js
import AdaptiveStore from 'ember-simple-auth/session-stores/adaptive';

export default class SessionStore extends AdaptiveStore {}
```

then __the session service can be injected wherever
needed in the application__. In order to display login/logout buttons depending
on the current session state, inject the service into the respective controller
or component and __query its
Expand Down Expand Up @@ -702,6 +719,7 @@ If you're an `ember-mocha` user, we can recommend to check out this
## Other guides

* [Managing current User](guides/managing-current-user.md)
* [Upgrading to v7](guides/upgrade-to-v7.md)
* [Upgrading to v4](guides/upgrade-to-v4.md)
* [Upgrading to v3](guides/upgrade-to-v3.md)

Expand Down
40 changes: 38 additions & 2 deletions guides/upgrade-to-v7.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
### tl;dr
## tl;dr

Release 7.0.0 doesn't contain any new features and the API haven't really changed.
It focuses on housekeeping, modernizing the codebase and introducing Typescript to our library.
The biggest change was getting rid of as much "classic" Ember syntax as possible and get onto ES6 classes.

### Extending ember-simple-auth's classes
There are some not-so-painful breaking changes however, please refer to the following document.

## Extending ember-simple-auth's classes

Most if not all of the public API is ES6 classes, as a result you'll have to change how ESA's classes are extended in your codebases.
Here's an example based on the OAuth2PasswordGrant authenticator.
Expand Down Expand Up @@ -32,3 +34,37 @@ export default class OAuth2 extends OAuth2PasswordGrant {
serverTokenRevocationEndpoint = `${config.apiHost}/revoke`;
}
```

## Default session-store and service are no longer automatically injected.

This change is made due to processing problems found here [ember-simple-auth/#2888](https://github.com/mainmatter/ember-simple-auth/pull/2888) and [shipshapecode/swach#1736](https://github.com/shipshapecode/swach/pull/1736).
It's been a problem for a long time and with Ember-Data and Ember itself being more explicit around dependencies, we're making the change too.

The only thing that ESA will continue to export is the initializer, they aren't usually imported and extended by users so they shouldn't cause problems as long as Ember still supports it.

### Migration guide:

Add `app/services/session.js` or `app/services/session.ts`

```js
import Service from 'ember-simple-auth/services/session';

export default class SessionService extends Service {}
```

Add `app/session-stores/application.js` or `app/session-stores/application.ts`

```js
import AdaptiveStore from 'ember-simple-auth/session-stores/adaptive';

export default class SessionStore extends AdaptiveStore {}
```

## Removed RSVP

Async APIs were built on top of RSVP.Promise, we're no longer relying on it and use the native Promise instead.

## Deprecated `responseJSON` and `responseText` fields returned by OAuth2PasswordGrantAuthenticator.

For historical reasons, when Ajax was still in use. OAuth2PasswordGrantAuthenticator adds `responseJSON` and `responseText` properties to the response returned by its #authenticated method.
These properties are deprecated and will be removed with later releases.
3 changes: 2 additions & 1 deletion packages/classic-test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"ember-engines": "0.11.0",
"ember-engines-router-service": "0.6.0",
"ember-fetch": "8.1.2",
"ember-inflector": "5.0.2",
"ember-load-initializers": "2.1.2",
"ember-maybe-import-regenerator": "1.0.0",
"ember-qunit": "7.0.0",
Expand All @@ -54,7 +55,7 @@
"globals": "15.12.0",
"handlebars": "4.7.8",
"loader.js": "4.7.0",
"my-engine": "workspace:../classic-test-app/lib/my-engine",
"my-engine": "workspace:./lib/my-engine",
"npm-run-all2": "7.0.2",
"pretender": "3.4.7",
"qunit": "2.23.1",
Expand Down
7 changes: 1 addition & 6 deletions packages/ember-simple-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,7 @@
"type": "addon",
"main": "addon-main.cjs",
"app-js": {
"./initializers/ember-simple-auth.js": "./dist/_app_/initializers/ember-simple-auth.js",
"./services/session.js": "./dist/_app_/services/session.js",
"./session-stores/application.js": "./dist/_app_/session-stores/application.js",
"./utils/is-fastboot.js": "./dist/_app_/utils/is-fastboot.js",
"./utils/location.js": "./dist/_app_/utils/location.js",
"./utils/objects-are-equal.js": "./dist/_app_/utils/objects-are-equal.js"
"./initializers/ember-simple-auth.js": "./dist/_app_/initializers/ember-simple-auth.js"
}
},
"exports": {
Expand Down
7 changes: 1 addition & 6 deletions packages/ember-simple-auth/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ export default {
// These are the modules that should get reexported into the traditional
// "app" tree. Things in here should also be in publicEntrypoints above, but
// not everything in publicEntrypoints necessarily needs to go here.
addon.appReexports([
'services/session.js',
'utils/**/*.js',
'session-stores/application.js',
'initializers/ember-simple-auth.js',
]),
addon.appReexports(['initializers/ember-simple-auth.js']),

// Follow the V2 Addon rules about dependencies. Your code can import from
// `dependencies` and `peerDependencies` as well as standard Ember-provided
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import type SessionService from 'test-app/services/session';

export default class ApplicationIndexController extends Controller {
@service session;
@service declare session: SessionService;
}
13 changes: 0 additions & 13 deletions packages/test-app/app/services/session.js

This file was deleted.

18 changes: 18 additions & 0 deletions packages/test-app/app/services/session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { inject as service } from '@ember/service';
import Session from 'ember-simple-auth/services/session';

export default class SessionService extends Session {
@service sessionAccount: any;

handleAuthentication(routeAfterInvalidation: string) {
super.handleAuthentication(routeAfterInvalidation);

this.sessionAccount.loadCurrentUser().catch(() => (this as any).invalidate());
}
}

declare module '@ember/service' {
interface Registry {
session: SessionService;
}
}
4 changes: 2 additions & 2 deletions packages/test-app/app/session-stores/application.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Cookie from 'ember-simple-auth/session-stores/cookie';
import CookieStore from 'ember-simple-auth/session-stores/cookie';

export default Cookie.extend();
export default class ApplicationStore extends CookieStore {}
3 changes: 2 additions & 1 deletion packages/test-app/babel.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"plugins": [
"@embroider/addon-dev/template-colocation-plugin",
["@babel/plugin-transform-typescript", { "allowDeclareFields": true }],
["@babel/plugin-proposal-decorators", { "legacy": true }],
"@babel/plugin-proposal-class-properties"
"@babel/plugin-proposal-class-properties",
]
}
2 changes: 1 addition & 1 deletion packages/test-app/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function (defaults) {
let app = new EmberApp(defaults, {});
let app = new EmberApp(defaults, { 'ember-cli-babel': { enableTypeScriptTransform: true } });

// Use `app.import` to add additional libraries to the generated
// output files.
Expand Down
15 changes: 12 additions & 3 deletions packages/test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:*:fix\"",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"lint:types": "tsc --noEmit",
"start": "ember serve",
"start:fastboot": "NODE_ENV=production node fastboot-server.js",
"start:demo-api": "node server/demo-api.js",
Expand All @@ -17,13 +18,22 @@
"test:fastboot": "ember fastboot:test"
},
"devDependencies": {
"@babel/eslint-parser": "7.25.9",
"@babel/plugin-transform-typescript": "7.26.3",
"@ember/legacy-built-in-components": "0.5.0",
"@ember/optional-features": "2.2.0",
"@ember/string": "3.1.1",
"@ember/test-helpers": "3.3.1",
"@embroider/test-setup": "4.0.0",
"@glimmer/component": "1.1.2",
"@glimmer/tracking": "1.1.2",
"@glint/core": "1.5.0",
"@glint/environment-ember-loose": "1.5.0",
"@glint/environment-ember-template-imports": "1.5.0",
"@tsconfig/ember": "3.0.8",
"@types/ember__service": "4.0.9",
"@typescript-eslint/eslint-plugin": "8.18.1",
"@typescript-eslint/parser": "8.18.1",
"body-parser": "1.20.3",
"bootstrap": "5.3.3",
"broccoli-asset-rev": "3.0.0",
Expand All @@ -44,6 +54,7 @@
"ember-engines": "0.11.0",
"ember-engines-router-service": "0.6.0",
"ember-fetch": "8.1.2",
"ember-inflector": "5.0.2",
"ember-load-initializers": "2.1.2",
"ember-maybe-import-regenerator": "1.0.0",
"ember-qunit": "7.0.0",
Expand All @@ -65,6 +76,7 @@
"qunit": "2.23.1",
"qunit-dom": "2.0.0",
"torii": "1.0.0-beta.2",
"typescript": "5.7.2",
"webpack": "5.96.1"
},
"fastbootDependencies": [
Expand All @@ -73,8 +85,5 @@
],
"ember": {
"edition": "octane"
},
"dependencies": {
"@babel/eslint-parser": "^7.24.7"
}
}
23 changes: 23 additions & 0 deletions packages/test-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "@tsconfig/ember/tsconfig.json",
"compilerOptions": {
"target": "es2020",
"module": "esnext",
// The combination of `baseUrl` with `paths` allows Ember's classic package
// layout, which is not resolvable with the Node resolution algorithm, to
// work with TypeScript.
"baseUrl": ".",
"experimentalDecorators": true,

"paths": {
"test-app/tests/*": ["tests/*"],
"test-app/*": ["app/*"],
"*": ["types/*"]
},
"types": ["ember-source/types"]
},
"glint": {
"environment": "ember-loose"
},
"include": ["app", "tests"]
}
1 change: 1 addition & 0 deletions packages/test-app/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@glint/environment-ember-loose';
3 changes: 3 additions & 0 deletions packages/test-esa/app/services/session.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Service from 'ember-simple-auth/services/session';

export default class SessionService extends Service {}
3 changes: 3 additions & 0 deletions packages/test-esa/app/session-stores/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Adaptive from 'ember-simple-auth/session-stores/adaptive';

export default class AdaptiveStore extends Adaptive {}
Loading
Loading