Skip to content

Commit

Permalink
Merged the auth provider types
Browse files Browse the repository at this point in the history
  • Loading branch information
Kræn Hansen committed Jun 10, 2020
1 parent 3162a9a commit a559969
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 35 deletions.
9 changes: 4 additions & 5 deletions packages/realm-web/src/auth-providers/ApiKeyAuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import { Transport } from "../transports";
import { deserialize } from "../utils/ejson";

/** @inheritdoc */
export class ApiKeyAuthProvider
implements Realm.AuthProviders.ApiKeyAuthProvider {
export class ApiKeyAuthProvider implements Realm.Auth.ApiKeyProvider {
/**
* The transport used to send requests to services.
*/
Expand All @@ -38,7 +37,7 @@ export class ApiKeyAuthProvider
}

/** @inheritdoc */
create(name: string): Promise<Realm.AuthProviders.ApiKey> {
create(name: string): Promise<Realm.Auth.ApiKey> {
return this.transport
.fetch({
method: "POST",
Expand All @@ -48,7 +47,7 @@ export class ApiKeyAuthProvider
}

/** @inheritdoc */
get(keyId: Realm.ObjectId): Promise<Realm.AuthProviders.ApiKey> {
get(keyId: Realm.ObjectId): Promise<Realm.Auth.ApiKey> {
return this.transport
.fetch({
method: "GET",
Expand All @@ -58,7 +57,7 @@ export class ApiKeyAuthProvider
}

/** @inheritdoc */
list(): Promise<Realm.AuthProviders.ApiKey[]> {
list(): Promise<Realm.Auth.ApiKey[]> {
return this.transport.fetch({ method: "GET" }).then(deserialize);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Transport } from "../transports";

/** @inheritdoc */
export class EmailPasswordAuthProvider
implements Realm.AuthProviders.EmailPasswordAuthProvider {
implements Realm.Auth.EmailPasswordProvider {
/**
* The underlying transport.
*/
Expand Down
2 changes: 1 addition & 1 deletion types/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ declare namespace Realm {
/**
* This object allows API keys associated with the user to be retrieved, created, enabled and disabled.
*/
readonly apiKeys: Realm.Auth.APIKeys;
readonly apiKeys: Realm.Auth.ApiKeyProvider;

/**
* Log out the user.
Expand Down
18 changes: 9 additions & 9 deletions types/auth-providers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ declare namespace Realm {
*/
interface AuthProviders {
/** Authentication provider where users identify using email and password. */
emailPassword: Realm.AuthProviders.EmailPasswordAuthProvider;
emailPassword: Realm.Auth.EmailPasswordProvider;
/** Authentication provider where users identify using an API-key. */
apiKey: Realm.AuthProviders.ApiKeyAuthProvider;
apiKey: Realm.Auth.ApiKeyProvider;
}

namespace AuthProviders {
namespace Auth {
/**
* Authentication provider where users identify using email and password.
*/
interface EmailPasswordAuthProvider {
class EmailPasswordProvider {
/**
* Register a new user.
*
Expand Down Expand Up @@ -92,7 +92,7 @@ declare namespace Realm {
/**
* The representation of an API-key stored in the service.
*/
interface ApiKey {
type ApiKey = {
/**
* The internal identifier of the key.
*/
Expand All @@ -112,12 +112,12 @@ declare namespace Realm {
* When disabled, the key cannot authenticate.
*/
disabled: boolean;
}
};

/**
* Authentication provider where users identify using an API-key.
*/
interface ApiKeyAuthProvider {
class ApiKeyProvider {
/**
* Creates an API key that can be used to authenticate as the current user.
*
Expand All @@ -130,12 +130,12 @@ declare namespace Realm {
*
* @param keyId the id of the API key to fetch.
*/
get(keyId: ObjectId): Promise<ApiKey>;
fetch(keyId: ObjectId): Promise<ApiKey>;

/**
* Fetches the API keys associated with the current user.
*/
list(): Promise<ApiKey[]>;
fetchAll(): Promise<ApiKey[]>;

/**
* Deletes an API key associated with the current user.
Expand Down
19 changes: 0 additions & 19 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,25 +323,6 @@ declare namespace Realm {
readonly prototype: Results<any>;
};

namespace Auth {
class APIKeys {
createAPIKey(name: string): Promise<void>;
fetchAPIKey(id: string): Promise<Object>;
allAPIKeys(): Promise<Array<Object>>;
deleteAPIKey(id: string): Promise<void>;
enableAPIKey(id: string): Promise<void>;
disableAPIKey(id: string): Promise<void>;
}

class EmailPassword {
registerEmail(email: string, password: string): Promise<void>;
confirmUser(token: string, id: string): Promise<void>;
resendConfirmationEmail(email: string): Promise<void>;
sendResetPasswordEmail(email: string): Promise<void>;
resetPassword(password: string, token: string, id: string): Promise<void>;
}
}

interface UserMap {
[identity: string]: User
}
Expand Down

0 comments on commit a559969

Please sign in to comment.