Skip to content

Commit

Permalink
feat: logged devices
Browse files Browse the repository at this point in the history
  • Loading branch information
riipandi committed Aug 31, 2022
1 parent c0f4ad1 commit 1c44283
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 46 deletions.
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[package]
name = "otentik-authenticator"
version = "0.6.1"
version = "0.7.0"
description = "Open Source two factor authenticator"
authors = ["Aris Ripandi <[email protected]>"]
license = "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub(crate) fn menu() -> Menu {
// App Menu (macOS)
// ---------------------------------------------------------------------------------------------
let about_menu = AboutMetadata::new()
.version(String::from("0.6.1"))
.version(String::from("0.7.0"))
.authors(vec![String::from("Aris Ripandi")])
.comments(String::from("Open Source two factor authenticator"))
.copyright(String::from("Copyright © Aris Ripandi"))
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "Authenticator",
"version": "0.6.1"
"version": "0.7.0"
},
"tauri": {
"allowlist": {
Expand Down
26 changes: 13 additions & 13 deletions apps/desktop/src/screens/AuthScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const AuthScreen = () => {
<div className={classNames(actionIsLogin ? 'py-12' : 'py-0', 'flex min-h-full items-center justify-center px-6')}>
<div className="w-full max-w-sm">
<div>
<h2 className="mt-8 text-center text-xl font-semibold tracking-tight text-white">
<h2 className="mt-8 text-center text-2xl font-semibold tracking-tight text-white">
{actionIsLogin ? 'Sign in to continue' : 'Create account'}
</h2>
</div>
Expand Down Expand Up @@ -143,18 +143,7 @@ export const AuthScreen = () => {
</div>
</form>

<div className="absolute left-0 bottom-0 flex w-full flex-col items-center justify-center space-y-3 py-10">
{/* <p className='text-center text-sm text-gray-300'>
Forgot password?{' '}
<a
href='https://otentik.app/recovery?ref=authenticator'
className='font-medium text-brand-500 hover:text-brand-600'
rel='noreferrer noopener'
target='_blank'
>
Reset
</a>
</p> */}
<div className="absolute left-0 bottom-0 flex w-full flex-col items-center justify-center space-y-4 py-8">
<p className="text-center text-sm text-gray-300">
{actionIsLogin ? "Dont' have account? " : 'Already have account? '}
<button
Expand All @@ -165,6 +154,17 @@ export const AuthScreen = () => {
{actionIsLogin ? 'Register' : 'Login'}
</button>
</p>
<p className="text-center text-sm text-gray-300">
Forgot password?{' '}
<a
href="https://vault.otentik.app/recovery?ref=authenticator"
className="text-brand-500 hover:text-brand-600 font-medium"
rel="noreferrer noopener"
target="_blank"
>
Reset
</a>
</p>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/screens/LockScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const LockScreen = () => {
// Store hashed passphrase in localStorage
const hashedPassphrase = await md5Hash(passphrase)
await localData.set('passphrase', hashedPassphrase)
// await updateDeviceInfo() // Update device information.
await updateDeviceInfo() // Update device information.

setError(null)
setLoading(false)
Expand Down
35 changes: 9 additions & 26 deletions apps/desktop/src/utils/supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,19 @@ export const addSingleCollection = async (data: any) => {
export const storeDeviceInfo = async () => {
const { device_uuid, os_platform, os_version, host_name } = await invoke('get_device_info')
const session = sbClient.auth.session()
const time = new Date().toISOString()

const user_id = session?.user?.id
const unique_id = await invoke('generate_udevice_id', { uid: user_id })
const prepared = { user_id, device_uuid, unique_id, os_platform, os_version, host_name }

console.log('UNIQUE_ID', unique_id)

const prepared = {
user_id,
device_uuid,
unique_id,
os_platform,
os_version,
host_name,
activated_at: time,
last_online_at: time,
}

const { error, status } = await sbClient.from('devices').upsert(prepared, { onConflict: 'unique_id' })
console.log('DEBUG', status, error)
// return await sbClient.from('devices').insert(prepared).single()
return await sbClient.from('devices').upsert(prepared, { onConflict: 'unique_id' })
}

// export const updateDeviceInfo = async () => {
// const { device_uuid } = await invoke('get_device_info')
// const session = sbClient.auth.session()
// const time = new Date().toISOString()
export const updateDeviceInfo = async () => {
const session = sbClient.auth.session()
const user_id = session?.user?.id
const unique_id = await invoke('generate_udevice_id', { uid: user_id })
const time = new Date().toISOString()

// return await sbClient
// .from('devices')
// .update({ last_online_at: time })
// .match({ user_id: session?.user?.id, device_uuid })
// }
return await sbClient.from('devices').update({ last_online_at: time }).match({ user_id, unique_id })
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ create table devices (
id BIGSERIAL PRIMARY KEY,
user_id uuid references auth.users not null,
device_uuid uuid not null,
unique_id varchar(24) not null,
unique_id char(24) not null,
os_platform varchar(255) not null,
os_version varchar(255) not null,
host_name varchar(255) not null,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "otentik",
"version": "0.6.1",
"version": "0.7.0",
"license": "Apache-2.0",
"private": true,
"scripts": {
Expand Down

0 comments on commit 1c44283

Please sign in to comment.