feat: create randomId helper and use everywhere
Co-authored-by: konrad <konrad@kola-entertainments.de>
This commit is contained in:
parent
3750b0f78b
commit
35c861b711
4 changed files with 13 additions and 7 deletions
|
@ -28,6 +28,8 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import {createRandomID} from '@/helpers/randomId'
|
||||||
|
|
||||||
const DEFAULT_COLORS = [
|
const DEFAULT_COLORS = [
|
||||||
'#1973ff',
|
'#1973ff',
|
||||||
'#7F23FF',
|
'#7F23FF',
|
||||||
|
@ -37,11 +39,6 @@ const DEFAULT_COLORS = [
|
||||||
'#00db60',
|
'#00db60',
|
||||||
]
|
]
|
||||||
|
|
||||||
function createRandomID() {
|
|
||||||
const ID_LENGTH = 9
|
|
||||||
return Math.random().toString(36).substr(2, ID_LENGTH)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'colorPicker',
|
name: 'colorPicker',
|
||||||
data() {
|
data() {
|
||||||
|
|
|
@ -21,12 +21,14 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import {createRandomID} from '@/helpers/randomId'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'fancycheckbox',
|
name: 'fancycheckbox',
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
checked: false,
|
checked: false,
|
||||||
checkBoxId: 'fancycheckbox' + Math.random(),
|
checkBoxId: `fancycheckbox_${createRandomID()}`,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
|
5
src/helpers/randomId.ts
Normal file
5
src/helpers/randomId.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
const DEFAULT_ID_LENGTH = 9
|
||||||
|
|
||||||
|
export function createRandomID(idLength = DEFAULT_ID_LENGTH) {
|
||||||
|
return Math.random().toString(36).substr(2, idLength)
|
||||||
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
|
import {createRandomID} from '@/helpers/randomId'
|
||||||
|
|
||||||
interface Provider {
|
interface Provider {
|
||||||
name: string
|
name: string
|
||||||
key: string
|
key: string
|
||||||
|
@ -6,7 +8,7 @@ interface Provider {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const redirectToProvider = (provider: Provider, redirectUrl: string) => {
|
export const redirectToProvider = (provider: Provider, redirectUrl: string) => {
|
||||||
const state = Math.random().toString(36).substring(2, 24)
|
const state = createRandomID(24)
|
||||||
localStorage.setItem('state', state)
|
localStorage.setItem('state', state)
|
||||||
|
|
||||||
window.location.href = `${provider.authUrl}?client_id=${provider.clientId}&redirect_uri=${redirectUrl}${provider.key}&response_type=code&scope=openid email profile&state=${state}`
|
window.location.href = `${provider.authUrl}?client_id=${provider.clientId}&redirect_uri=${redirectUrl}${provider.key}&response_type=code&scope=openid email profile&state=${state}`
|
||||||
|
|
Loading…
Reference in a new issue