<commit_before>import {
	get,
	set,
	getProperties,
	setProperties,
	computed,
	inject,
	Evented,
	Service
} from "ember";
import { twitch } from "config";
import nwWindow from "nwjs/Window";
import { openBrowser } from "nwjs/Shell";
import { all } from "utils/contains";
import HttpServer from "utils/node/http/HttpServer";
import OAuthResponseRedirect from "root/oauth-redirect.html";


const { service } = inject;
const {
	oauth: {
		/** @type {String} */
		"base-uri": baseuri,
		/** @type {String} */
		"client-id": clientid,
		/** @type {Number} */
		"server-port": serverport,
		/** @type {String} */
		"redirect-uri": redirecturi,
		/** @type {String[]} */
		"scope": scope
	}
} = twitch;

const reToken = /^[a-z\d]{30}$/i;


export default Service.extend( Evented, {
	store: service(),

	session: null,
	server: null,

	url: computed(function() {
		let redirect = redirecturi.replace( "{server-port}", String( serverport ) );

		return baseuri
			.replace( "{client-id}", clientid )
			.replace( "{redirect-uri}", encodeURIComponent( redirect ) )
			.replace( "{scope}", scope.join( "+" ) );
	}),


	init() {
		const store = get( this, "store" );

		store.findAll( "auth" )
			.then( records => records.content.length
				? records.objectAt( 0 )
				: store.createRecord( "auth", { id: 1 } ).save()
			)
			.then( session => {
				set( this, "session", session );

				// startup auto login
				let token = get( session, "access_token" );
				this.login( token, true )
					.catch( () => {} );

				// trigger event after calling login, so `isPending` can be set first
				this.trigger( "initialized" );
			});
	},
<commit_msg>Use findOrCreateRecord store method in AuthService<commit_after>import {
	get,
	set,
	getProperties,
	setProperties,
	computed,
	inject,
	Evented,
	Service
} from "ember";
import { twitch } from "config";
import nwWindow from "nwjs/Window";
import { openBrowser } from "nwjs/Shell";
import { all } from "utils/contains";
import HttpServer from "utils/node/http/HttpServer";
import OAuthResponseRedirect from "root/oauth-redirect.html";


const { service } = inject;
const {
	oauth: {
		/** @type {String} */
		"base-uri": baseuri,
		/** @type {String} */
		"client-id": clientid,
		/** @type {Number} */
		"server-port": serverport,
		/** @type {String} */
		"redirect-uri": redirecturi,
		/** @type {String[]} */
		"scope": scope
	}
} = twitch;

const reToken = /^[a-z\d]{30}$/i;


export default Service.extend( Evented, {
	store: service(),

	session: null,
	server: null,

	url: computed(function() {
		let redirect = redirecturi.replace( "{server-port}", String( serverport ) );

		return baseuri
			.replace( "{client-id}", clientid )
			.replace( "{redirect-uri}", encodeURIComponent( redirect ) )
			.replace( "{scope}", scope.join( "+" ) );
	}),


	init() {
		const store = get( this, "store" );
		store.findOrCreateRecord( "auth" )
			.then( session => {
				set( this, "session", session );

				// startup auto login
				let token = get( session, "access_token" );
				this.login( token, true )
					.catch( () => {} );

				// trigger event after calling login, so `isPending` can be set first
				this.trigger( "initialized" );
			});
	},

{'fraction_non_alphanumeric': 0.17685794920037629, 'fraction_numerical': 0.0018814675446848542, 'mean_word_length': 3.4428969359331476, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 8, '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': '4017375', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1071, 'n_words': 281}