|
| 1 | +import { AUTHENTICATION } from '../constants/action_types' |
| 2 | +import { |
| 3 | +loginToken, |
| 4 | +logout as logoutEndpoint, |
| 5 | +emailConfirmation as emailConfirmationEndpoint, |
| 6 | +checkConfirmationCode as checkConfirmationCodeEndpoint, |
| 7 | +forgotPassword, |
| 8 | +resetPassword, |
| 9 | +refreshAuthToken, |
| 10 | +webappToken, |
| 11 | +} from '../networking/api' |
| 12 | +import * as ENV from '../../env' |
| 13 | + |
| 14 | +export function clearAuthToken() { |
| 15 | +return { |
| 16 | +type: AUTHENTICATION.CLEAR_AUTH_TOKEN, |
| 17 | +} |
| 18 | +} |
| 19 | + |
| 20 | +export function getUserCredentials(email, password, meta) { |
| 21 | +return { |
| 22 | +type: AUTHENTICATION.USER, |
| 23 | +payload: { |
| 24 | +endpoint: loginToken(), |
| 25 | +method: 'POST', |
| 26 | +body: { |
| 27 | +email, |
| 28 | +password, |
| 29 | +grant_type: 'password', |
| 30 | +client_id: ENV.AUTH_CLIENT_ID, |
| 31 | +}, |
| 32 | +}, |
| 33 | +meta, |
| 34 | +} |
| 35 | +} |
| 36 | + |
| 37 | +export function logout() { |
| 38 | +return { |
| 39 | +type: AUTHENTICATION.LOGOUT, |
| 40 | +payload: { |
| 41 | +endpoint: logoutEndpoint(), |
| 42 | +method: 'DELETE', |
| 43 | +}, |
| 44 | +} |
| 45 | +} |
| 46 | + |
| 47 | +export function refreshAuthenticationToken(refreshToken) { |
| 48 | +return { |
| 49 | +type: AUTHENTICATION.REFRESH, |
| 50 | +payload: { |
| 51 | +endpoint: refreshAuthToken(refreshToken), |
| 52 | +method: 'POST', |
| 53 | +body: { |
| 54 | +refresh_token: refreshToken, |
| 55 | +grant_type: 'refresh_token', |
| 56 | +client_id: ENV.AUTH_CLIENT_ID, |
| 57 | +}, |
| 58 | +}, |
| 59 | +} |
| 60 | +} |
| 61 | + |
| 62 | +export function sendForgotPasswordRequest(email) { |
| 63 | +return { |
| 64 | +type: AUTHENTICATION.FORGOT_PASSWORD, |
| 65 | +payload: { |
| 66 | +endpoint: forgotPassword(), |
| 67 | +method: 'POST', |
| 68 | +body: { |
| 69 | +email, |
| 70 | +}, |
| 71 | +}, |
| 72 | +} |
| 73 | +} |
| 74 | + |
| 75 | +export function sendResetPasswordRequest(password, resetPasswordToken) { |
| 76 | +return { |
| 77 | +type: AUTHENTICATION.RESET_PASSWORD, |
| 78 | +payload: { |
| 79 | +endpoint: resetPassword(), |
| 80 | +method: 'PUT', |
| 81 | +body: { |
| 82 | +password, |
| 83 | +reset_password_token: resetPasswordToken, |
| 84 | +}, |
| 85 | +}, |
| 86 | +} |
| 87 | +} |
| 88 | + |
| 89 | +export function sendEmailForConfirmation(email) { |
| 90 | +return { |
| 91 | +type: AUTHENTICATION.SEND_EMAIL_FOR_CONFIRMATION, |
| 92 | +payload: { |
| 93 | +body: { email }, |
| 94 | +endpoint: emailConfirmationEndpoint(), |
| 95 | +method: 'POST', |
| 96 | +}, |
| 97 | +} |
| 98 | +} |
| 99 | + |
| 100 | +export function checkConfirmationCode({ email, code }) { |
| 101 | +return { |
| 102 | +type: AUTHENTICATION.CHECK_CONFIRMATION_CODE, |
| 103 | +payload: { |
| 104 | +body: { email, code }, |
| 105 | +endpoint: checkConfirmationCodeEndpoint(), |
| 106 | +method: 'POST', |
| 107 | +}, |
| 108 | +} |
| 109 | +} |
| 110 | + |
| 111 | +export function signIn(email, password) { |
| 112 | +return { |
| 113 | +type: AUTHENTICATION.SIGN_IN, |
| 114 | +payload: { |
| 115 | +method: 'POST', |
| 116 | +email, |
| 117 | +password, |
| 118 | +}, |
| 119 | +} |
| 120 | +} |
| 121 | + |
| 122 | +export function fetchPublicToken() { |
| 123 | +return { |
| 124 | +type: AUTHENTICATION.PUBLIC, |
| 125 | +payload: { |
| 126 | +endpoint: webappToken(), |
| 127 | +method: 'GET', |
| 128 | +}, |
| 129 | +} |
| 130 | +} |
| 131 | + |
0 commit comments