## 概要 [Task1597: 画面実装(ユーザー認証画面/認証完了画面)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/1597) - アカウントへのユーザ追加でメール認証URLから認証を実行した際の画面を実装しました。 - 完了後の画面はアカウント登録のものをそのまま流用しています。 ## レビューポイント - 認証APIからのレスポンスはアカウント登録と同様のものを想定して、完了画面をそのまま流用していますが問題ないでしょうか。 - 画面のパスを`/mail-confirm/user`としましたが問題ないでしょうか? ## UIの変更 - アカウント登録の認証完了画面と同様 ## 動作確認状況 - ローカルで確認 - 認証APIでアカウント登録と同様のレスポンスを想定
72 lines
1.7 KiB
TypeScript
72 lines
1.7 KiB
TypeScript
import { createAsyncThunk } from "@reduxjs/toolkit";
|
|
import type { RootState } from "app/store";
|
|
import { UsersApi } from "../../api/api";
|
|
import { Configuration } from "../../api/configuration";
|
|
import { ErrorObject, createErrorObject } from "../../common/errors";
|
|
|
|
export const verifyAsync = createAsyncThunk<
|
|
{
|
|
/* Empty Object */
|
|
},
|
|
{
|
|
jwt: string;
|
|
},
|
|
{
|
|
// rejectした時の返却値の型
|
|
rejectValue: {
|
|
error: ErrorObject;
|
|
};
|
|
}
|
|
>("verify/verifyAsync", async (args, thunkApi) => {
|
|
const { jwt } = args;
|
|
// apiのConfigurationを取得する
|
|
const { getState } = thunkApi;
|
|
const state = getState() as RootState;
|
|
const { configuration } = state.auth;
|
|
const config = new Configuration(configuration);
|
|
const usersApi = new UsersApi(config);
|
|
|
|
try {
|
|
await usersApi.confirmUser({ token: jwt });
|
|
return {};
|
|
} catch (e) {
|
|
// e ⇒ errorObjectに変換
|
|
const error = createErrorObject(e);
|
|
|
|
return thunkApi.rejectWithValue({ error });
|
|
}
|
|
});
|
|
|
|
export const userVerifyAsync = createAsyncThunk<
|
|
{
|
|
/* Empty Object */
|
|
},
|
|
{
|
|
jwt: string;
|
|
},
|
|
{
|
|
// rejectした時の返却値の型
|
|
rejectValue: {
|
|
error: ErrorObject;
|
|
};
|
|
}
|
|
>("verify/userVerifyAsync", async (args, thunkApi) => {
|
|
const { jwt } = args;
|
|
// apiのConfigurationを取得する
|
|
const { getState } = thunkApi;
|
|
const state = getState() as RootState;
|
|
const { configuration } = state.auth;
|
|
const config = new Configuration(configuration);
|
|
const usersApi = new UsersApi(config);
|
|
|
|
try {
|
|
await usersApi.confirmUserAndInitPassword({ token: jwt });
|
|
return {};
|
|
} catch (e) {
|
|
// e ⇒ errorObjectに変換
|
|
const error = createErrorObject(e);
|
|
|
|
return thunkApi.rejectWithValue({ error });
|
|
}
|
|
});
|