<commit_before>import React, { Component } from 'react'

import * as actions from '../store/actions'
import Cookies from 'cookies'
import skill from '../index'
import DevControls from '../../components/DevControls/DevControls'
import qs from 'qs'
import lang from '../helpers/lang'

const Page = Wrapped => {
	// const ConnectedWrapped = connect(mapStateToProps, mapDispatchToProps)(Wrapped)
	const ConnectedWrapped = Wrapped

	return class extends Component {
		// Everything here is run server side
		static async getInitialProps({
			pathname,
			query,
			asPath,
			store,
			res,
			req,
			isServer
		}) {
			let props = { pathname, query, asPath, skill }

			const cookies = new Cookies(req, res, { secure: true })
			const jwt = query.jwt || cookies.get('jwt')
			if (jwt) {
				try {
					await store.dispatch(actions.auth.go(jwt))

					// only save cookie if a new one has been passed
					if (query.jwt) {
						cookies.set('jwt', query.jwt)
					}
				} catch (err) {
					console.error(err)
					console.warn('Error fetching user from jwt')
				}
			}

			const state = store.getState()
			props = {
				devMode: state.config.DEV_MODE,
				...props,
				...state
			}

			if (props.auth && !props.auth.error) {
				props.auth.role =
				(props.config.DEV_MODE && cookies.get('devRole')) || props.auth.role
			}
			
			
			if (ConnectedWrapped.getInitialProps) {
				props = {
					...props,
					...(await ConnectedWrapped.getInitialProps.call(this, ...arguments))
				}
			}
			
			let redirect = props.redirect || false
		
			// make sure we have a user AND a location if we are not flagged as public
			if (
				!redirect &&
				!props.public &&
				(!props.auth || !props.auth.role || props.auth.error)
			) {
				redirect = '/unauthorized'
			} else if (!redirect && !props.public) {
				// check role against first part of path
				const role = props.auth.role
				const firstPart = props.pathname.split('/')[1]

				let queryString = { ...query }
				delete queryString.jwt
				queryString = qs.stringify(queryString)

				// we are at '/' then redirect to the corresponding role's path
				if (props.pathname === '/') {
					redirect = `/${role}?${queryString}`
				} else if (role !== firstPart) {
					redirect = `/unauthorized`
				}
			}

			if (redirect) {
				res.redirect = redirect
				res.end()
				return
			}

			// We can only return a plain object here because it is passed to the browser
			// No circular dependencies
			return props
		}
		componentDidMount() {
			// make sure we are being loaded inside sb
			if (window.self === window.top) {
				console.error('NOT LOADED FROM SPRUCEBOT!! BAIL BAIL BAIL')
			}
		}

		render() {
			if (this.props.devMode) {
				return (
					<div>
						<DevControls auth={this.props.auth} />
						<ConnectedWrapped
							{...this.props}
							skill={skill}
							getText={lang.get.bind(lang)}
						/>
					</div>
				)
			}
			return (
				<ConnectedWrapped
					{...this.props}
					skill={skill}
					getText={lang.get.bind(lang)}
				/>
			)
		}
	}
}

export default Wrapped => Page(Wrapped)
<commit_msg>formatting<commit_after>import React, { Component } from 'react'

import * as actions from '../store/actions'
import Cookies from 'cookies'
import skill from '../index'
import DevControls from '../../components/DevControls/DevControls'
import qs from 'qs'
import lang from '../helpers/lang'

const Page = Wrapped => {
	// const ConnectedWrapped = connect(mapStateToProps, mapDispatchToProps)(Wrapped)
	const ConnectedWrapped = Wrapped

	return class extends Component {
		// Everything here is run server side
		static async getInitialProps({
			pathname,
			query,
			asPath,
			store,
			res,
			req,
			isServer
		}) {
			let props = { pathname, query, asPath, skill }

			const cookies = new Cookies(req, res, { secure: true })
			const jwt = query.jwt || cookies.get('jwt')
			if (jwt) {
				try {
					await store.dispatch(actions.auth.go(jwt))

					// only save cookie if a new one has been passed
					if (query.jwt) {
						cookies.set('jwt', query.jwt)
					}
				} catch (err) {
					console.error(err)
					console.warn('Error fetching user from jwt')
				}
			}

			const state = store.getState()
			props = {
				devMode: state.config.DEV_MODE,
				...props,
				...state
			}

			if (props.auth && !props.auth.error) {
				props.auth.role =
					(props.config.DEV_MODE && cookies.get('devRole')) || props.auth.role
			}

			if (ConnectedWrapped.getInitialProps) {
				props = {
					...props,
					...(await ConnectedWrapped.getInitialProps.call(this, ...arguments))
				}
			}

			let redirect = props.redirect || false

			// make sure we have a user AND a location if we are not flagged as public
			if (
				!redirect &&
				!props.public &&
				(!props.auth || !props.auth.role || props.auth.error)
			) {
				redirect = '/unauthorized'
			} else if (!redirect && !props.public) {
				// check role against first part of path
				const role = props.auth.role
				const firstPart = props.pathname.split('/')[1]

				let queryString = { ...query }
				delete queryString.jwt
				queryString = qs.stringify(queryString)

				// we are at '/' then redirect to the corresponding role's path
				if (props.pathname === '/') {
					redirect = `/${role}?${queryString}`
				} else if (role !== firstPart) {
					redirect = `/unauthorized`
				}
			}

			if (redirect) {
				res.redirect = redirect
				res.end()
				return
			}

			// We can only return a plain object here because it is passed to the browser
			// No circular dependencies
			return props
		}
		componentDidMount() {
			// make sure we are being loaded inside sb
			if (window.self === window.top) {
				console.error('NOT LOADED FROM SPRUCEBOT!! BAIL BAIL BAIL')
			}
		}

		render() {
			if (this.props.devMode) {
				return (
					<div>
						<DevControls auth={this.props.auth} />
						<ConnectedWrapped
							{...this.props}
							skill={skill}
							getText={lang.get.bind(lang)}
						/>
					</div>
				)
			}
			return (
				<ConnectedWrapped
					{...this.props}
					skill={skill}
					getText={lang.get.bind(lang)}
				/>
			)
		}
	}
}

export default Wrapped => Page(Wrapped)

{'fraction_non_alphanumeric': 0.13469652710159039, 'fraction_numerical': 0.0003245699448231094, 'mean_word_length': 2.4353400222965442, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2458194', 'n_tokens_mistral': 2545, 'n_tokens_neox': 1967, 'n_words': 528}