-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from tago-io/feature/auth-system
Feature: Authentication and Setup
- Loading branch information
Showing
187 changed files
with
8,185 additions
and
5,298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Application } from "express"; | ||
import { z } from "zod"; | ||
import { IAccountCreate, zAccountCreate } from "@tago-io/tcore-sdk/types"; | ||
import { createAccount, getAccountByToken, login } from "../../Services/Account/Account"; | ||
import APIController, { ISetupController, warm } from "../APIController"; | ||
|
||
const zAccountLoginBody = z.object({ | ||
username: z.string(), | ||
password: z.string(), | ||
}); | ||
|
||
/** | ||
* Lists all the database plugins. | ||
*/ | ||
class AccountLogin extends APIController<z.infer<typeof zAccountLoginBody>, void, void> { | ||
setup: ISetupController = { | ||
allowTokens: [{ permission: "any", resource: "anonymous" }], | ||
zBodyParser: zAccountLoginBody, | ||
}; | ||
|
||
public async main() { | ||
const { username, password } = this.bodyParams; | ||
const response = await login(username, password); | ||
this.body = response; | ||
} | ||
} | ||
|
||
/** | ||
* Checks if there is at least one account registered. | ||
*/ | ||
class InfoAccount extends APIController<void, void, void> { | ||
setup: ISetupController = { | ||
allowTokens: [{ permission: "read", resource: "account" }], | ||
}; | ||
|
||
public async main() { | ||
const response = await getAccountByToken(this.rawToken as string); | ||
this.body = response; | ||
} | ||
} | ||
|
||
/** | ||
* Creates a new device. | ||
*/ | ||
class CreateAccount extends APIController<IAccountCreate, void, void> { | ||
setup: ISetupController = { | ||
allowTokens: [{ permission: "write", resource: "account" }], | ||
zBodyParser: zAccountCreate, | ||
}; | ||
|
||
public async main() { | ||
const response = await createAccount(this.bodyParams); | ||
this.body = response; | ||
} | ||
} | ||
|
||
/** | ||
* Exports the auth routes. | ||
*/ | ||
export default (app: Application) => { | ||
app.get("/account", warm(InfoAccount)); | ||
app.post("/account", warm(CreateAccount)); | ||
app.post("/account/login", warm(AccountLogin)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.