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

チュートリアルドキュメントの修正 #105

Open
wants to merge 3 commits into
base: feature/tutorial_improvements
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 55 additions & 54 deletions docs/tutorial/authentication-preference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -354,23 +354,19 @@ app.use(

Do it like this.

Next, prepare an outlet for the callback from the authentication screen.
And for PHP, we will prepare an endpoint to handle the callback from the authentication screen.

Earlier, in the SaaSus development console, we defined the callback destination as
Earlier, in the SaaSus Development Console, we defined the callback URL as

For PHP, [http://localhost/callback](http://localhost/callback)
[http://localhost/callback](http://localhost/callback)

For Next.js, [http://localhost:3000/callback](http://localhost:3000/callback)
so we’ll set it up to receive at /callback.

So we will make it possible to receive the callback at /callback.

Similarly, for PHP, add the following to the last line of api/routes/web.php.

For Next.js, create api/routes/callback.ts and write the following.
Add the following to the last line of api/routes/web.php

```mdx-code-block
<Tabs>
<TabItem value="php" label="PHP" default>
<TabItem value="php" label="PHP">
```

```php
Expand All @@ -380,64 +376,71 @@ Route::get('/callback', 'AntiPatternInc\Saasus\Laravel\Controllers\CallbackContr

```mdx-code-block
</TabItem>
<TabItem value="nodejs" label="Node.js">
</Tabs>
```

```js
import express from "express";
const router = express.Router();
import { CallbackRouteFunction } from "saasus-sdk";
Furthermore, to be able to use the View provided by the SaaSus SDK,

router.get("/", CallbackRouteFunction);
Add the path to api/config/view.php.

export { router };
```mdx-code-block
<Tabs>
<TabItem value="php" label="PHP" default>
```

```php
'paths' => [
resource_path('views'),
# ↓Add this line: Directory of views provided by SaaSus SDK
resource_path('../vendor/saasus-platform/saasus-sdk-php/src/Laravel/Views'),
],
```

```mdx-code-block
</TabItem>
</Tabs>
```

Furthermore, to be able to use the View provided by the SaaSus SDK,
For Next.js,

in PHP, add the path to api/config/view.php.
In the previously created front/src/pages/callback/index.tsx, the /api/callback endpoint is used to obtain authentication information.

In Next.js, create api/views/callback.ejs and write the following.
To handle this endpoint, follow these steps to configure it.

Add the import statement and app.use to api/app.ts to define the route.

```mdx-code-block
<Tabs>
<TabItem value="php" label="PHP" default>
<TabItem value="nodejs" label="Node.js">
```

```php
'paths' => [
resource_path('views'),
# ↓Add this line: Directory of views provided by SaaSus SDK
resource_path('../vendor/saasus-platform/saasus-sdk-php/src/Laravel/Views'),
],
```js
import { router as apiCallbackRouter } from "./routes/api/callback";

// Other code omitted

app.use("/api/callback", apiCallbackRouter);
```

```mdx-code-block
</TabItem>
</Tabs>
```

To implement the /api/callback endpoint, create api/routes/api/callback.ts and add the following code.
```mdx-code-block
<Tabs>
<TabItem value="nodejs" label="Node.js">
```

```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
```js
import express from "express";
const router = express.Router();
import { CallbackRouteFunction } from "saasus-sdk";

<title>Auth Callback</title>
</head>
router.get("/", CallbackRouteFunction);

<body>
<script>
location.href = "/chat";
</script>
</body>
</html>
export { router };
```

```mdx-code-block
Expand All @@ -449,7 +452,7 @@ With the settings up to this point, the authentication information set in SaaSus

For PHP, add a Request argument to index in api/app/Http/Controllers/MessageController.php and use dd to check if userinfo is included in $request.

For Next.js, add a Request argument to getChats in api/controllers/chat.ts and use console.log to check if userinfo is included in req.
For Next.js, add a Request argument to getBoard in api/controllers/api/board.ts and use console.log to check if userinfo is included in req.

```mdx-code-block
<Tabs>
Expand All @@ -469,9 +472,9 @@ For Next.js, add a Request argument to getChats in api/controllers/chat.ts and u
```

```js
const getChats = async (req: Request, res: Response) => {
const getBoard = async (req: Request, res: Response) => {
// Check whether user information is being passed from SaaSus Platform
console.log(req.userinfo);
console.log(req.userInfo);
```

```mdx-code-block
Expand Down Expand Up @@ -547,7 +550,7 @@ For the setting method, please check [Customizing Authentication Pages such as L

For PHP, api/app/Http/Controllers/MessageController.php

For Next.js, api/controllers/chat.ts
For Next.js, api/controllers/api/board.ts

This is the main process, so let's add the process to make it multi-tenant compatible here.

Expand All @@ -574,21 +577,19 @@ Let's rewrite the whole part below.
```

```js
const getChats = async (req: Request, res: Response) => {
const getBoard = async (req: Request, res: Response) => {
try {
const messages = await db.Messages.findAll({
where: {
tenant_id: req.userInfo?.tenants[0].id,
},
});
res.render("chat", {
messages: messages,
plans: PLANS,
tenant_name: TENANT_NAME,
});
return res.json(messages);
} catch (error) {
console.error(error);
res.redirect("/chat");
return res
.status(500)
.send({ redirect_url: process.env.SAASUS_LOGIN_URL || "" });
}
};
```
Expand Down Expand Up @@ -632,7 +633,7 @@ Next is the posting part.
```

```js
const postChats = async (req: Request, res: Response) => {
const post = async (req: Request, res: Response) => {
const mes = req.body.message;
const tenantId = req.userInfo?.tenants[0].id || "";
const userName =
Expand All @@ -643,10 +644,10 @@ const postChats = async (req: Request, res: Response) => {
user_id: userName,
message: mes,
});
return res.status(201).send();
} catch (error) {
console.error(error);
}
res.redirect("/chat");
};
```

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/configuring-sdk-for-saasus-platform.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Create a .env file by copying the .env.example file in the api directory, and ed
SAASUS_SAAS_ID="98tjo3wifaoua (Screen SaaS ID)"
SAASUS_API_KEY="kjntowjfoasnkjntwonsflajsno4as (Screen API Key)"
SAASUS_SECRET_KEY=" (Screen client secret)"
SAASUS_LOGIN_URL="https://auth.sample.saasus.jp/ (Login screen URL)"
SAASUS_LOGIN_URL=" (Login screen URL)"
SAASUS_AUTH_MODE="api"(For Next.js, please write)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ Earlier, we set a different upper limit for the number of comments for each pric

Now, get the maximum number associated with this pricing plan for each tenant and set a limit.

In the Blade version, the post method in api/app/Http/Controllers/MessageController.php is
For the Blade version, let’s modify the post method in api/app/Http/Controllers/MessageController.php.

In the Next.js version, rewrite the postChats method in api/controllers/chat.ts as follows.
For the Next.js version, let’s add an import statement to api/controllers/api/board.ts and modify the post method.

<Tabs>
<TabItem value="php" label="PHP" default>
Expand Down Expand Up @@ -78,14 +78,19 @@ In the Next.js version, rewrite the postChats method in api/controllers/chat.ts

</TabItem>

<TabItem value="typescript" label="Typescript">
```typescript
const postChats = async (req: Request, res: Response) => {
<TabItem value="nodejs" label="Node.js">
```js
import { UpdateMeteringUnitTimestampCountNowParam } from "saasus-sdk/dist/generated/Pricing";
import { findUpperCountByMeteringUnitName, PricingClient } from "saasus-sdk";

// Other code omitted

const post = async (req: Request, res: Response) => {
const mes = req.body.message;
const tenantId = req.userInfo?.tenants[0].id || "";
const planId = req.userInfo?.tenants[0].plan_id || "";
const userName =
req.userInfo?.tenants[0].user_attribute.username || "テストユーザー";
req.userInfo?.tenants[0].user_attribute.username || "test user";
try {
const pricingClient = new PricingClient();
const pricingPlan = await pricingClient.pricingPlansApi.getPricingPlan(
Expand Down Expand Up @@ -126,10 +131,10 @@ const postChats = async (req: Request, res: Response) => {
param
);
}
return res.status(201).send();
} catch (error) {
console.error(error);
}
res.redirect("/chat");
};
```
</TabItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ hidden: false
createdAt: "Fri Jan 20 2023 01:47:13 GMT+0000 (Coordinated Universal Time)"
updatedAt: "Thu Dec 07 2023 01:25:35 GMT+0000 (Coordinated Universal Time)"
---
## Setting measurement units, feature menus, and pricing plans

## Metering Units Setting

| Unit Name | Unit Display Name | Unit Description |
|:-----------|:-------------|:-----------------|
| comment_count | comment_count | Comment Count |

![07](/img/tutorial/manage-rate-plans/setting-measurement-units-function-menus-and-price-plans/setting-measurement-units-function-menus-and-price-plans-07.png)

## Basic Pricing

Measurement Unit: Fixed Unit
Expand Down
38 changes: 38 additions & 0 deletions docs/tutorial/prepare-saasus-platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,44 @@ By setting a domain on SaaSus Platform, you can set it as the base domain for au
For information on how to set up your domain, please see [Domain Name Preference](../saas-development-console/domain-name-preference).
:::

### Define Additional Attributes for Users

Next, define user attributes.

Click "User Attribute Definition" on the side menu.

![06](/img/tutorial/prepare-saasus-platform/prepare-saasus-platform-06.png)

On the default SaaS Platform managed SaaS users only have user IDs (UUIDs) and email addresses. If this is not enough, users can be assigned additional attributes.

SaaS designers need to consider which user attributes should be on the SaaS Platform side and which attributes should be on the SaaS side.

For example, if you want to manage all user information on the SaaS Platform side, define the required additional attributes in the SaaS Platform. However, there are cases where you do not want to manage important information such as personal information on the SaaS Platform side, or you want to perform various aggregations based on additional user attributes. In that case, it is more flexible to require only authentication on the SaaS Platform side, manage user information on the SaaS side based on the user master, and associate the UUID with the authentication information on the SaaS Platform side.

For this example, the sample application requires a username, so let's define an attribute called "username".

Click the "+ Create User Attribute" to display the dialog for creating user attributes

The attribute name is used as a key for identification on the SaaS application (code) side. Therefore, it is important to enter in English.

Display name is described so that the attribute can be easily understood

Type specifies the data type.

For the sample application, set as follows

- Attribute Name: username
- Display Name: Username
- Type: String

After entering, press the "Create" button

![07](/img/tutorial/prepare-saasus-platform/prepare-saasus-platform-07.png)

User attributes added.

![08](/img/tutorial/prepare-saasus-platform/prepare-saasus-platform-08.png)

:::info
Please refer to the following page for the main registration settings required when actually developing a SaaS application.<br/>
[Declare Additional Attribute To User](../saas-development-console/declare-additional-attribute-to-user)<br/>
Expand Down
Loading