mirror of
https://github.com/mozilla/fxa.git
synced 2025-12-13 20:36:41 +01:00
Because: * There's an error case some users experience where it appears a client-side OTP code check is valid but our server then rejects it. We mishandle the error state and tell the user 2FA setup was successful This commit: * Updates our front-end OTP check in fxa-settings to use the same library our backend uses (otplib, but for the browser) * Has auth-server throw an error if the TOTP code is invalid during set up, and handles it properly in the front-end by checking for an error, not updating apollo cache to show a successful TOTP setup if there is an error, and displays an error for the user closes FXA-12035
140 lines
4.2 KiB
JavaScript
140 lines
4.2 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
const { resolve } = require('path');
|
|
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
|
|
const webpack = require('webpack');
|
|
|
|
const allFxa = resolve(__dirname, '../../');
|
|
const allLibs = resolve(__dirname, '../../libs/');
|
|
const importPaths = [
|
|
allFxa,
|
|
allLibs,
|
|
resolve(__dirname, '../../../node_modules'),
|
|
];
|
|
const additionalJSImports = {
|
|
'fxa-react': resolve(__dirname, '../'),
|
|
'fxa-shared': resolve(__dirname, '../../fxa-shared'),
|
|
};
|
|
|
|
const customizeWebpackConfig = ({ config }) => ({
|
|
...config,
|
|
plugins: [
|
|
...config.plugins,
|
|
new webpack.ProvidePlugin({
|
|
process: 'process/browser',
|
|
}),
|
|
new webpack.ProvidePlugin({
|
|
buffer: ['buffer', 'Buffer'],
|
|
Buffer: ['buffer', 'Buffer'],
|
|
}),
|
|
],
|
|
resolve: {
|
|
...config.resolve,
|
|
plugins: [
|
|
...(config.resolve.plugins || []),
|
|
new TsconfigPathsPlugin({ configFile: './tsconfig.json' }),
|
|
].map((plugin) => {
|
|
// Rebuild ModuleScopePlugin with some additional allowed paths
|
|
if (
|
|
plugin.constructor &&
|
|
plugin.constructor.name === 'ModuleScopePlugin'
|
|
) {
|
|
plugin.appSrcs.push(...importPaths);
|
|
}
|
|
return plugin;
|
|
}),
|
|
// Register a few more extensions to resolve
|
|
extensions: [...config.resolve.extensions, '.svg', '.scss', '.css', '.png'],
|
|
// Add aliases to some packages shared across the project
|
|
alias: { ...config.resolve.alias, ...additionalJSImports },
|
|
fallback: {
|
|
...config.fallback,
|
|
fs: false,
|
|
path: false,
|
|
crypto: require.resolve('crypto-browserify'),
|
|
stream: require.resolve('stream-browserify'),
|
|
},
|
|
},
|
|
module: {
|
|
...config.module,
|
|
rules: [
|
|
{
|
|
// HACK: convert *all* rules into oneOf so that these first few
|
|
// rules override others that overlap
|
|
oneOf: [
|
|
// Add support for our .scss stylesheets
|
|
{
|
|
test: /\.s[ac]ss$/i,
|
|
use: ['style-loader', 'css-loader', 'sass-loader'],
|
|
},
|
|
// Support using SVGs as React components
|
|
// fxa-react stories need this since that package does not have the
|
|
// webpack config from CRA that includes svgr
|
|
{
|
|
test: /\.svg$/,
|
|
use: [
|
|
{
|
|
loader: require.resolve('@svgr/webpack'),
|
|
options: {
|
|
svgoConfig: {
|
|
plugins: [
|
|
{
|
|
name: 'preset-default',
|
|
params: {
|
|
overrides: {
|
|
// disable plugins
|
|
removeViewBox: false,
|
|
},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
},
|
|
},
|
|
{
|
|
loader: require.resolve('file-loader'),
|
|
options: { name: 'static/media/[name].[hash:8].[ext]' },
|
|
},
|
|
],
|
|
},
|
|
// Support images and fonts
|
|
{
|
|
test: /\.(png|woff|woff2)$/,
|
|
use: [
|
|
{
|
|
loader: require.resolve('file-loader'),
|
|
},
|
|
],
|
|
},
|
|
// Include the rest of the existing rules with some tweaks...
|
|
...config.module.rules.map((rule) => {
|
|
// Replace Storybook built-in Typescript support.
|
|
if (rule.test && rule.test.test && rule.test.test('.tsx')) {
|
|
return {
|
|
test: /\.(ts|tsx)$/,
|
|
loader: require.resolve('babel-loader'),
|
|
options: {
|
|
presets: [['react-app', { flow: false, typescript: true }]],
|
|
plugins: [
|
|
[
|
|
'@babel/plugin-transform-typescript',
|
|
{ allowDeclareFields: true },
|
|
],
|
|
],
|
|
},
|
|
};
|
|
}
|
|
return rule;
|
|
}),
|
|
],
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
module.exports = {
|
|
customizeWebpackConfig,
|
|
};
|