feat: create randomId helper and use everywhere
Co-authored-by: konrad <konrad@kola-entertainments.de>
This commit is contained in:
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 {
|
||||
name: string
|
||||
key: string
|
||||
@ -6,7 +8,7 @@ interface Provider {
|
||||
}
|
||||
|
||||
export const redirectToProvider = (provider: Provider, redirectUrl: string) => {
|
||||
const state = Math.random().toString(36).substring(2, 24)
|
||||
const state = createRandomID(24)
|
||||
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}`
|
||||
|
Reference in New Issue
Block a user